// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.network;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.ConnectException;
import java.nio.ByteBuffer;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import se.krka.kahlua.vm.KahluaTable;
import se.krka.kahlua.vm.KahluaTableIterator;
import zombie.Lua.LuaEventManager;
import zombie.Lua.LuaManager;
import zombie.asset.AssetManagers;
import zombie.audio.GameSound;
import zombie.audio.GameSoundClip;
import zombie.characters.Faction;
import zombie.characters.IsoGameCharacter;
import zombie.characters.IsoPlayer;
import zombie.characters.IsoZombie;
import zombie.characters.Safety;
import zombie.characters.SafetySystemManager;
import zombie.characters.SurvivorDesc;
import zombie.characters.SurvivorFactory;
import zombie.characters.BodyDamage.BodyPart;
import zombie.characters.BodyDamage.BodyPartType;
import zombie.characters.skills.CustomPerks;
import zombie.characters.skills.PerkFactory;
import zombie.commands.CommandBase;
import zombie.commands.PlayerType;
import zombie.core.Color;
import zombie.core.Core;
import zombie.core.Languages;
import zombie.core.PerformanceSettings;
import zombie.core.ProxyPrintStream;
import zombie.core.Rand;
import zombie.core.ThreadGroups;
import zombie.core.Translator;
import zombie.core.backup.ZipBackup;
import zombie.core.logger.ExceptionLogger;
import zombie.core.logger.LoggerManager;
import zombie.core.math.PZMath;
import zombie.core.network.ByteBufferReader;
import zombie.core.network.ByteBufferWriter;
import zombie.core.profiling.PerformanceProfileFrameProbe;
import zombie.core.profiling.PerformanceProfileProbe;
import zombie.core.raknet.RakNetPeerInterface;
import zombie.core.raknet.RakVoice;
import zombie.core.raknet.UdpConnection;
import zombie.core.raknet.UdpEngine;
import zombie.core.skinnedmodel.ModelManager;
import zombie.core.skinnedmodel.advancedanimation.AnimNodeAssetManager;
import zombie.core.skinnedmodel.model.AiSceneAsset;
import zombie.core.skinnedmodel.model.AiSceneAssetManager;
import zombie.core.skinnedmodel.model.AnimationAsset;
import zombie.core.skinnedmodel.model.AnimationAssetManager;
import zombie.core.skinnedmodel.model.MeshAssetManager;
import zombie.core.skinnedmodel.model.Model;
import zombie.core.skinnedmodel.model.ModelAssetManager;
import zombie.core.skinnedmodel.model.ModelMesh;
import zombie.core.skinnedmodel.model.jassimp.JAssImpImporter;
import zombie.core.skinnedmodel.population.BeardStyles;
import zombie.core.skinnedmodel.population.ClothingDecals;
import zombie.core.skinnedmodel.population.ClothingItem;
import zombie.core.skinnedmodel.population.ClothingItemAssetManager;
import zombie.core.skinnedmodel.population.HairStyles;
import zombie.core.skinnedmodel.population.OutfitManager;
import zombie.core.skinnedmodel.visual.ItemVisuals;
import zombie.core.stash.StashSystem;
import zombie.core.textures.ColorInfo;
import zombie.core.textures.Texture;
import zombie.core.textures.TextureAssetManager;
import zombie.core.textures.TextureID;
import zombie.core.textures.TextureIDAssetManager;
import zombie.core.utils.UpdateLimit;
import zombie.core.znet.PortMapper;
import zombie.core.znet.SteamGameServer;
import zombie.core.znet.SteamUtils;
import zombie.core.znet.SteamWorkshop;
import zombie.debug.DebugLog;
import zombie.debug.DebugOptions;
import zombie.debug.DebugType;
import zombie.debug.LogSeverity;
import zombie.erosion.ErosionMain;
import zombie.gameStates.IngameState;
import zombie.globalObjects.SGlobalObjectNetwork;
import zombie.globalObjects.SGlobalObjects;
import zombie.inventory.CompressIdenticalItems;
import zombie.inventory.InventoryItem;
import zombie.inventory.InventoryItemFactory;
import zombie.inventory.ItemContainer;
import zombie.inventory.ItemPickerJava;
import zombie.inventory.RecipeManager;
import zombie.inventory.types.AlarmClock;
import zombie.inventory.types.DrainableComboItem;
import zombie.inventory.types.Food;
import zombie.inventory.types.HandWeapon;
import zombie.inventory.types.InventoryContainer;
import zombie.inventory.types.Radio;
import zombie.iso.BuildingDef;
import zombie.iso.IsoCamera;
import zombie.iso.IsoChunk;
import zombie.iso.IsoChunkMap;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoMetaCell;
import zombie.iso.IsoMetaGrid;
import zombie.iso.IsoMovingObject;
import zombie.iso.IsoObject;
import zombie.iso.IsoUtils;
import zombie.iso.IsoWorld;
import zombie.iso.LosUtil;
import zombie.iso.ObjectsSyncRequests;
import zombie.iso.RoomDef;
import zombie.iso.SpawnPoints;
import zombie.iso.Vector2;
import zombie.iso.Vector3;
import zombie.iso.areas.NonPvpZone;
import zombie.iso.areas.SafeHouse;
import zombie.iso.areas.isoregion.IsoRegions;
import zombie.iso.objects.BSFurnace;
import zombie.iso.objects.IsoBarricade;
import zombie.iso.objects.IsoCompost;
import zombie.iso.objects.IsoDeadBody;
import zombie.iso.objects.IsoDoor;
import zombie.iso.objects.IsoFire;
import zombie.iso.objects.IsoFireManager;
import zombie.iso.objects.IsoGenerator;
import zombie.iso.objects.IsoLightSwitch;
import zombie.iso.objects.IsoMannequin;
import zombie.iso.objects.IsoThumpable;
import zombie.iso.objects.IsoTrap;
import zombie.iso.objects.IsoWaveSignal;
import zombie.iso.objects.IsoWindow;
import zombie.iso.objects.IsoWorldInventoryObject;
import zombie.iso.objects.RainManager;
import zombie.iso.sprite.IsoSprite;
import zombie.iso.sprite.IsoSpriteManager;
import zombie.iso.weather.ClimateManager;
import zombie.network.chat.ChatServer;
import zombie.network.packets.ActionPacket;
import zombie.network.packets.AddXp;
import zombie.network.packets.CleanBurn;
import zombie.network.packets.DeadPlayerPacket;
import zombie.network.packets.DeadZombiePacket;
import zombie.network.packets.Disinfect;
import zombie.network.packets.EventPacket;
import zombie.network.packets.PlaySoundPacket;
import zombie.network.packets.PlayWorldSoundPacket;
import zombie.network.packets.PlayerDataRequestPacket;
import zombie.network.packets.PlayerPacket;
import zombie.network.packets.RemoveBullet;
import zombie.network.packets.RemoveCorpseFromMap;
import zombie.network.packets.RemoveGlass;
import zombie.network.packets.RequestDataPacket;
import zombie.network.packets.SafetyPacket;
import zombie.network.packets.StartFire;
import zombie.network.packets.Stitch;
import zombie.network.packets.StopSoundPacket;
import zombie.network.packets.SyncClothingPacket;
import zombie.network.packets.SyncInjuriesPacket;
import zombie.network.packets.SyncNonPvpZonePacket;
import zombie.network.packets.SyncSafehousePacket;
import zombie.network.packets.ValidatePacket;
import zombie.network.packets.WaveSignal;
import zombie.network.packets.hit.HitCharacterPacket;
import zombie.popman.MPDebugInfo;
import zombie.popman.NetworkZombieManager;
import zombie.popman.NetworkZombiePacker;
import zombie.popman.ZombiePopulationManager;
import zombie.radio.ZomboidRadio;
import zombie.radio.devices.DeviceData;
import zombie.sandbox.CustomSandboxOptions;
import zombie.savefile.ServerPlayerDB;
import zombie.scripting.ScriptManager;
import zombie.util.PZSQLUtils;
import zombie.util.PublicServerUtil;
import zombie.util.StringUtils;
import zombie.util.Type;
import zombie.vehicles.BaseVehicle;
import zombie.vehicles.Clipper;
import zombie.vehicles.PolygonalMap2;
import zombie.vehicles.VehicleManager;
import zombie.vehicles.VehiclePart;
import zombie.vehicles.VehiclesDB2;
import zombie.world.moddata.GlobalModData;
import zombie.worldMap.WorldMapRemotePlayer;
import zombie.worldMap.WorldMapRemotePlayers;

public class GameServer {
    public static final int MAX_PLAYERS = 512;
    public static final int TimeLimitForProcessPackets = 70;
    public static final int PacketsUpdateRate = 200;
    public static final int FPS = 10;
    private static final HashMap<String, GameServer.CCFilter> ccFilters = new HashMap();
    public static int test = 432432;
    public static int DEFAULT_PORT = 16261;
    public static int UDPPort = 16262;
    public static String IPCommandline = null;
    public static int PortCommandline = -1;
    public static int UDPPortCommandline = -1;
    public static Boolean SteamVACCommandline;
    public static boolean GUICommandline;
    public static boolean bServer = false;
    public static boolean bCoop = false;
    public static boolean bDebug = false;
    public static boolean bSoftReset = false;
    public static UdpEngine udpEngine;
    public static final HashMap<Short, Long> IDToAddressMap = new HashMap();
    public static final HashMap<Short, IsoPlayer> IDToPlayerMap = new HashMap();
    public static final ArrayList<IsoPlayer> Players = new ArrayList();
    public static float timeSinceKeepAlive = 0.0F;
    public static int MaxTicksSinceKeepAliveBeforeStall = 60;
    public static final HashSet<UdpConnection> DebugPlayer = new HashSet();
    public static int ResetID = 0;
    public static final ArrayList<String> ServerMods = new ArrayList();
    public static final ArrayList<Long> WorkshopItems = new ArrayList();
    public static String[] WorkshopInstallFolders;
    public static long[] WorkshopTimeStamps;
    public static String ServerName = "servertest";
    public static final DiscordBot discordBot = new DiscordBot(
        ServerName, (string0, string1) -> ChatServer.getInstance().sendMessageFromDiscordToGeneralChat(string0, string1)
    );
    public static String checksum = "";
    public static String GameMap = "Muldraugh, KY";
    public static boolean bFastForward;
    public static final HashMap<String, Integer> transactionIDMap = new HashMap();
    public static final ObjectsSyncRequests worldObjectsServerSyncReq = new ObjectsSyncRequests(false);
    public static String ip = "127.0.0.1";
    static int count = 0;
    private static final UdpConnection[] SlotToConnection = new UdpConnection[512];
    private static final HashMap<IsoPlayer, Long> PlayerToAddressMap = new HashMap();
    private static final ArrayList<Integer> alreadyRemoved = new ArrayList();
    private static boolean bDone;
    private static boolean launched = false;
    private static final ArrayList<String> consoleCommands = new ArrayList();
    private static final HashMap<Long, IZomboidPacket> MainLoopPlayerUpdate = new HashMap();
    private static final ConcurrentLinkedQueue<IZomboidPacket> MainLoopPlayerUpdateQ = new ConcurrentLinkedQueue();
    private static final ConcurrentLinkedQueue<IZomboidPacket> MainLoopNetDataHighPriorityQ = new ConcurrentLinkedQueue();
    private static final ConcurrentLinkedQueue<IZomboidPacket> MainLoopNetDataQ = new ConcurrentLinkedQueue();
    private static final ArrayList<IZomboidPacket> MainLoopNetData2 = new ArrayList();
    private static final HashMap<Short, Vector2> playerToCoordsMap = new HashMap();
    private static final HashMap<Short, Integer> playerMovedToFastMap = new HashMap();
    private static ByteBuffer large_file_bb = ByteBuffer.allocate(2097152);
    private static long previousSave = Calendar.getInstance().getTimeInMillis();
    private String poisonousBerry = null;
    private String poisonousMushroom = null;
    private String difficulty = "Hardcore";
    private static int droppedPackets = 0;
    private static int countOfDroppedPackets = 0;
    private static int countOfDroppedConnections = 0;
    public static UdpConnection removeZombiesConnection = null;
    private static UpdateLimit calcCountPlayersInRelevantPositionLimiter = new UpdateLimit(2000L);
    private static UpdateLimit sendWorldMapPlayerPositionLimiter = new UpdateLimit(1000L);
    public static LoginQueue loginQueue = new LoginQueue();
    private static int mainCycleExceptionLogCount = 25;
    public static Thread MainThread;
    public static final ArrayList<IsoPlayer> tempPlayers = new ArrayList();

    public static void PauseAllClients() {
        String string = "[SERVERMSG] Server saving...Please wait";

        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
            PacketTypes.PacketType.StartPause.doPacket(byteBufferWriter);
            byteBufferWriter.putUTF(string);
            PacketTypes.PacketType.StartPause.send(udpConnection);
        }
    }

    public static void UnPauseAllClients() {
        String string = "[SERVERMSG] Server saved game...enjoy :)";

        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
            PacketTypes.PacketType.StopPause.doPacket(byteBufferWriter);
            byteBufferWriter.putUTF(string);
            PacketTypes.PacketType.StopPause.send(udpConnection);
        }
    }

    private static String parseIPFromCommandline(String[] string0, int int0, String string1) {
        if (int0 == string0.length - 1) {
            DebugLog.log("expected argument after \"" + string1 + "\"");
            System.exit(0);
        } else if (string0[int0 + 1].trim().isEmpty()) {
            DebugLog.log("empty argument given to \"\" + option + \"\"");
            System.exit(0);
        } else {
            String[] string2 = string0[int0 + 1].trim().split("\\.");
            if (string2.length == 4) {
                for (int int1 = 0; int1 < 4; int1++) {
                    try {
                        int int2 = Integer.parseInt(string2[int1]);
                        if (int2 < 0 || int2 > 255) {
                            DebugLog.log("expected IP address after \"" + string1 + "\", got \"" + string0[int0 + 1] + "\"");
                            System.exit(0);
                        }
                    } catch (NumberFormatException numberFormatException) {
                        DebugLog.log("expected IP address after \"" + string1 + "\", got \"" + string0[int0 + 1] + "\"");
                        System.exit(0);
                    }
                }
            } else {
                DebugLog.log("expected IP address after \"" + string1 + "\", got \"" + string0[int0 + 1] + "\"");
                System.exit(0);
            }
        }

        return string0[int0 + 1];
    }

    private static int parsePortFromCommandline(String[] string0, int _int, String string1) {
        if (_int == string0.length - 1) {
            DebugLog.log("expected argument after \"" + string1 + "\"");
            System.exit(0);
        } else if (string0[_int + 1].trim().isEmpty()) {
            DebugLog.log("empty argument given to \"" + string1 + "\"");
            System.exit(0);
        } else {
            try {
                return Integer.parseInt(string0[_int + 1].trim());
            } catch (NumberFormatException numberFormatException) {
                DebugLog.log("expected an integer after \"" + string1 + "\"");
                System.exit(0);
            }
        }

        return -1;
    }

    private static boolean parseBooleanFromCommandline(String[] string0, int _int, String string1) {
        if (_int == string0.length - 1) {
            DebugLog.log("expected argument after \"" + string1 + "\"");
            System.exit(0);
        } else if (string0[_int + 1].trim().isEmpty()) {
            DebugLog.log("empty argument given to \"" + string1 + "\"");
            System.exit(0);
        } else {
            String string2 = string0[_int + 1].trim();
            if ("true".equalsIgnoreCase(string2)) {
                return true;
            }

            if ("false".equalsIgnoreCase(string2)) {
                return false;
            }

            DebugLog.log("expected true or false after \"" + string1 + "\"");
            System.exit(0);
        }

        return false;
    }

    public static void setupCoop() throws FileNotFoundException {
        CoopSlave.init();
    }

    public static void main(String[] string0) {
        MainThread = Thread.currentThread();
        bServer = true;
        bSoftReset = System.getProperty("softreset") != null;

        for (int int0 = 0; int0 < string0.length; int0++) {
            if (string0[int0] != null) {
                if (string0[int0].startsWith("-cachedir=")) {
                    zombie.ZomboidFileSystem.instance.setCacheDir(string0[int0].replace("-cachedir=", "").trim());
                } else if (string0[int0].equals("-coop")) {
                    bCoop = true;
                }
            }
        }

        if (bCoop) {
            try {
                CoopSlave.initStreams();
            } catch (FileNotFoundException fileNotFoundException0) {
                fileNotFoundException0.printStackTrace();
            }
        } else {
            try {
                String string1 = zombie.ZomboidFileSystem.instance.getCacheDir() + File.separator + "server-console.txt";
                FileOutputStream fileOutputStream = new FileOutputStream(string1);
                PrintStream printStream = new PrintStream(fileOutputStream, true);
                System.setOut(new ProxyPrintStream(System.out, printStream));
                System.setErr(new ProxyPrintStream(System.err, printStream));
            } catch (FileNotFoundException fileNotFoundException1) {
                fileNotFoundException1.printStackTrace();
            }
        }

        DebugLog.init();
        LoggerManager.init();
        DebugLog.log("cachedir set to \"" + zombie.ZomboidFileSystem.instance.getCacheDir() + "\"");
        if (bCoop) {
            try {
                setupCoop();
                CoopSlave.status("UI_ServerStatus_Initialising");
            } catch (FileNotFoundException fileNotFoundException2) {
                fileNotFoundException2.printStackTrace();
                SteamUtils.shutdown();
                System.exit(37);
                return;
            }
        }

        PZSQLUtils.init();
        Clipper.init();
        Rand.init();
        if (System.getProperty("debug") != null) {
            bDebug = true;
            Core.bDebug = true;
        }

        DebugLog.General.println("version=%s demo=%s", Core.getInstance().getVersion(), false);
        DebugLog.General.println("revision=%s date=%s time=%s", "", "", "");

        for (int int1 = 0; int1 < string0.length; int1++) {
            if (string0[int1] != null) {
                if (!string0[int1].startsWith("-disablelog=")) {
                    if (string0[int1].startsWith("-debuglog=")) {
                        for (String string2 : string0[int1].replace("-debuglog=", "").split(",")) {
                            try {
                                DebugLog.setLogEnabled(DebugType.valueOf(string2), true);
                            } catch (IllegalArgumentException illegalArgumentException0) {
                            }
                        }
                    } else if (string0[int1].equals("-adminusername")) {
                        if (int1 == string0.length - 1) {
                            DebugLog.log("expected argument after \"-adminusername\"");
                            System.exit(0);
                        } else if (!ServerWorldDatabase.isValidUserName(string0[int1 + 1].trim())) {
                            DebugLog.log("invalid username given to \"-adminusername\"");
                            System.exit(0);
                        } else {
                            ServerWorldDatabase.instance.CommandLineAdminUsername = string0[int1 + 1].trim();
                            int1++;
                        }
                    } else if (string0[int1].equals("-adminpassword")) {
                        if (int1 == string0.length - 1) {
                            DebugLog.log("expected argument after \"-adminpassword\"");
                            System.exit(0);
                        } else if (string0[int1 + 1].trim().isEmpty()) {
                            DebugLog.log("empty argument given to \"-adminpassword\"");
                            System.exit(0);
                        } else {
                            ServerWorldDatabase.instance.CommandLineAdminPassword = string0[int1 + 1].trim();
                            int1++;
                        }
                    } else if (!string0[int1].startsWith("-cachedir=")) {
                        if (string0[int1].equals("-ip")) {
                            IPCommandline = parseIPFromCommandline(string0, int1, "-ip");
                            int1++;
                        } else if (string0[int1].equals("-gui")) {
                            GUICommandline = true;
                        } else if (string0[int1].equals("-nosteam")) {
                            System.setProperty("zomboid.steam", "0");
                        } else if (string0[int1].equals("-statistic")) {
                            int int2 = parsePortFromCommandline(string0, int1, "-statistic");
                            if (int2 >= 0) {
                                MPStatistic.getInstance().setPeriod(int2);
                                MPStatistic.getInstance().writeEnabled(true);
                            }
                        } else if (string0[int1].equals("-port")) {
                            PortCommandline = parsePortFromCommandline(string0, int1, "-port");
                            int1++;
                        } else if (string0[int1].equals("-udpport")) {
                            UDPPortCommandline = parsePortFromCommandline(string0, int1, "-udpport");
                            int1++;
                        } else if (string0[int1].equals("-steamvac")) {
                            SteamVACCommandline = parseBooleanFromCommandline(string0, int1, "-steamvac");
                            int1++;
                        } else if (string0[int1].equals("-servername")) {
                            if (int1 == string0.length - 1) {
                                DebugLog.log("expected argument after \"-servername\"");
                                System.exit(0);
                            } else if (string0[int1 + 1].trim().isEmpty()) {
                                DebugLog.log("empty argument given to \"-servername\"");
                                System.exit(0);
                            } else {
                                ServerName = string0[int1 + 1].trim();
                                int1++;
                            }
                        } else if (string0[int1].equals("-coop")) {
                            ServerWorldDatabase.instance.doAdmin = false;
                        } else {
                            DebugLog.log("unknown option \"" + string0[int1] + "\"");
                        }
                    }
                } else {
                    for (String string3 : string0[int1].replace("-disablelog=", "").split(",")) {
                        if ("All".equals(string3)) {
                            for (DebugType debugType : DebugType.values()) {
                                DebugLog.setLogEnabled(debugType, false);
                            }
                        } else {
                            try {
                                DebugLog.setLogEnabled(DebugType.valueOf(string3), false);
                            } catch (IllegalArgumentException illegalArgumentException1) {
                            }
                        }
                    }
                }
            }
        }

        DebugLog.log("server name is \"" + ServerName + "\"");
        String string4 = isWorldVersionUnsupported();
        if (string4 != null) {
            DebugLog.log(string4);
            CoopSlave.status(string4);
        } else {
            SteamUtils.init();
            RakNetPeerInterface.init();
            ZombiePopulationManager.init();

            try {
                zombie.ZomboidFileSystem.instance.init();
                Languages.instance.init();
                Translator.loadFiles();
            } catch (Exception exception0) {
                DebugLog.General.printException(exception0, "Exception Thrown", LogSeverity.Error);
                DebugLog.General.println("Server Terminated.");
            }

            ServerOptions.instance.init();
            initClientCommandFilter();
            if (PortCommandline != -1) {
                ServerOptions.instance.DefaultPort.setValue(PortCommandline);
            }

            if (UDPPortCommandline != -1) {
                ServerOptions.instance.UDPPort.setValue(UDPPortCommandline);
            }

            if (SteamVACCommandline != null) {
                ServerOptions.instance.SteamVAC.setValue(SteamVACCommandline);
            }

            DEFAULT_PORT = ServerOptions.instance.DefaultPort.getValue();
            UDPPort = ServerOptions.instance.UDPPort.getValue();
            if (CoopSlave.instance != null) {
                ServerOptions.instance.ServerPlayerID.setValue("");
            }

            if (SteamUtils.isSteamModeEnabled()) {
                String string5 = ServerOptions.instance.PublicName.getValue();
                if (string5 == null || string5.isEmpty()) {
                    ServerOptions.instance.PublicName.setValue("My PZ Server");
                }
            }

            String string6 = ServerOptions.instance.Map.getValue();
            if (string6 != null && !string6.trim().isEmpty()) {
                GameMap = string6.trim();
                if (GameMap.contains(";")) {
                    String[] string7 = GameMap.split(";");
                    string6 = string7[0];
                }

                Core.GameMap = string6.trim();
            }

            String string8 = ServerOptions.instance.Mods.getValue();
            if (string8 != null) {
                String[] string9 = string8.split(";");

                for (String string10 : string9) {
                    if (!string10.trim().isEmpty()) {
                        ServerMods.add(string10.trim());
                    }
                }
            }

            if (SteamUtils.isSteamModeEnabled()) {
                int int3 = ServerOptions.instance.SteamVAC.getValue() ? 3 : 2;
                if (!SteamGameServer.Init(IPCommandline, DEFAULT_PORT, UDPPort, int3, Core.getInstance().getSteamServerVersion())) {
                    SteamUtils.shutdown();
                    return;
                }

                SteamGameServer.SetProduct("zomboid");
                SteamGameServer.SetGameDescription("Project Zomboid");
                SteamGameServer.SetModDir("zomboid");
                SteamGameServer.SetDedicatedServer(true);
                SteamGameServer.SetMaxPlayerCount(ServerOptions.getInstance().getMaxPlayers());
                SteamGameServer.SetServerName(ServerOptions.instance.PublicName.getValue());
                SteamGameServer.SetMapName(ServerOptions.instance.Map.getValue());
                if (ServerOptions.instance.Public.getValue()) {
                    SteamGameServer.SetGameTags(CoopSlave.instance != null ? "hosted" : "");
                } else {
                    SteamGameServer.SetGameTags("hidden" + (CoopSlave.instance != null ? ";hosted" : ""));
                }

                SteamGameServer.SetKeyValue("description", ServerOptions.instance.PublicDescription.getValue());
                SteamGameServer.SetKeyValue("version", Core.getInstance().getVersion());
                SteamGameServer.SetKeyValue("open", ServerOptions.instance.Open.getValue() ? "1" : "0");
                SteamGameServer.SetKeyValue("public", ServerOptions.instance.Public.getValue() ? "1" : "0");
                String string11 = ServerOptions.instance.Mods.getValue();
                int int4 = 0;
                String[] string12 = string11.split(";");

                for (String string13 : string12) {
                    if (!StringUtils.isNullOrWhitespace(string13)) {
                        int4++;
                    }
                }

                if (string11.length() > 128) {
                    StringBuilder stringBuilder = new StringBuilder();
                    String[] string14 = string11.split(";");

                    for (String string15 : string14) {
                        if (stringBuilder.length() + 1 + string15.length() > 128) {
                            break;
                        }

                        if (stringBuilder.length() > 0) {
                            stringBuilder.append(';');
                        }

                        stringBuilder.append(string15);
                    }

                    string11 = stringBuilder.toString();
                }

                SteamGameServer.SetKeyValue("mods", string11);
                SteamGameServer.SetKeyValue("modCount", String.valueOf(int4));
                SteamGameServer.SetKeyValue("pvp", ServerOptions.instance.PVP.getValue() ? "1" : "0");
                if (bDebug) {
                }

                String string16 = ServerOptions.instance.WorkshopItems.getValue();
                if (string16 != null) {
                    String[] string17 = string16.split(";");

                    for (String string18 : string17) {
                        string18 = string18.trim();
                        if (!string18.isEmpty() && SteamUtils.isValidSteamID(string18)) {
                            WorkshopItems.add(SteamUtils.convertStringToSteamID(string18));
                        }
                    }
                }

                SteamWorkshop.init();
                SteamGameServer.LogOnAnonymous();
                SteamGameServer.EnableHeartBeats(true);
                DebugLog.log("Waiting for response from Steam servers");

                while (true) {
                    SteamUtils.runLoop();
                    int int5 = SteamGameServer.GetSteamServersConnectState();
                    if (int5 == SteamGameServer.STEAM_SERVERS_CONNECTED) {
                        if (!GameServerWorkshopItems.Install(WorkshopItems)) {
                            return;
                        }
                        break;
                    }

                    if (int5 == SteamGameServer.STEAM_SERVERS_CONNECTFAILURE) {
                        DebugLog.log("Failed to connect to Steam servers");
                        SteamUtils.shutdown();
                        return;
                    }

                    try {
                        Thread.sleep(100L);
                    } catch (InterruptedException interruptedException0) {
                    }
                }
            }

            ZipBackup.onStartup();
            ZipBackup.onVersion();
            int int6 = 0;

            try {
                ServerWorldDatabase.instance.create();
            } catch (ClassNotFoundException | SQLException sQLException) {
                sQLException.printStackTrace();
            }

            if (ServerOptions.instance.UPnP.getValue()) {
                DebugLog.log("Router detection/configuration starting.");
                DebugLog.log("If the server hangs here, set UPnP=false.");
                PortMapper.startup();
                if (PortMapper.discover()) {
                    DebugLog.log("UPnP-enabled internet gateway found: " + PortMapper.getGatewayInfo());
                    String string19 = PortMapper.getExternalAddress();
                    DebugLog.log("External IP address: " + string19);
                    DebugLog.log("trying to setup port forwarding rules...");
                    int int7 = 86400;
                    boolean boolean0 = true;
                    if (PortMapper.addMapping(DEFAULT_PORT, DEFAULT_PORT, "PZ Server default port", "UDP", int7, boolean0)) {
                        DebugLog.log(DebugType.Network, "Default port has been mapped successfully");
                    } else {
                        DebugLog.log(DebugType.Network, "Failed to map default port");
                    }

                    if (SteamUtils.isSteamModeEnabled()) {
                        int int8 = ServerOptions.instance.UDPPort.getValue();
                        if (PortMapper.addMapping(int8, int8, "PZ Server UDPPort", "UDP", int7, boolean0)) {
                            DebugLog.log(DebugType.Network, "AdditionUDPPort has been mapped successfully");
                        } else {
                            DebugLog.log(DebugType.Network, "Failed to map AdditionUDPPort");
                        }
                    }
                } else {
                    DebugLog.log(
                        DebugType.Network,
                        "No UPnP-enabled Internet gateway found, you must configure port forwarding on your gateway manually in order to make your server accessible from the Internet."
                    );
                }
            }

            Core.GameMode = "Multiplayer";
            bDone = false;
            DebugLog.log(DebugType.Network, "Initialising Server Systems...");
            CoopSlave.status("UI_ServerStatus_Initialising");

            try {
                doMinimumInit();
            } catch (Exception exception1) {
                DebugLog.General.printException(exception1, "Exception Thrown", LogSeverity.Error);
                DebugLog.General.println("Server Terminated.");
            }

            LosUtil.init(100, 100);
            ChatServer.getInstance().init();
            DebugLog.log(DebugType.Network, "Loading world...");
            CoopSlave.status("UI_ServerStatus_LoadingWorld");

            try {
                ClimateManager.setInstance(new ClimateManager());
                IsoWorld.instance.init();
            } catch (Exception exception2) {
                DebugLog.General.printException(exception2, "Exception Thrown", LogSeverity.Error);
                DebugLog.General.println("Server Terminated.");
                CoopSlave.status("UI_ServerStatus_Terminated");
                return;
            }

            File file = zombie.ZomboidFileSystem.instance.getFileInCurrentSave("z_outfits.bin");
            if (!file.exists()) {
                ServerOptions.instance.changeOption("ResetID", new Integer(Rand.Next(100000000)).toString());
            }

            try {
                SpawnPoints.instance.initServer2();
            } catch (Exception exception3) {
                exception3.printStackTrace();
            }

            LuaEventManager.triggerEvent("OnGameTimeLoaded");
            SGlobalObjects.initSystems();
            zombie.SoundManager.instance = new zombie.SoundManager();
            zombie.AmbientStreamManager.instance = new zombie.AmbientSoundManager();
            zombie.AmbientStreamManager.instance.init();
            ServerMap.instance.LastSaved = System.currentTimeMillis();
            VehicleManager.instance = new VehicleManager();
            ServerPlayersVehicles.instance.init();
            DebugOptions.instance.init();
            zombie.GameProfiler.init();

            try {
                startServer();
            } catch (ConnectException connectException) {
                connectException.printStackTrace();
                SteamUtils.shutdown();
                return;
            }

            if (SteamUtils.isSteamModeEnabled()) {
                DebugLog.log("##########\nServer Steam ID " + SteamGameServer.GetSteamID() + "\n##########");
            }

            UpdateLimit updateLimit = new UpdateLimit(100L);
            PerformanceSettings.setLockFPS(10);
            IngameState ingameState = new IngameState();
            float float0 = 0.0F;
            float[] float1 = new float[20];

            for (int int9 = 0; int9 < 20; int9++) {
                float1[int9] = (float)PerformanceSettings.getLockFPS();
            }

            float float2 = (float)PerformanceSettings.getLockFPS();
            long long0 = System.currentTimeMillis();
            long long1 = System.currentTimeMillis();
            if (!SteamUtils.isSteamModeEnabled()) {
                PublicServerUtil.init();
                PublicServerUtil.insertOrUpdate();
            }

            ServerLOS.init();
            NetworkAIParams.Init();
            int int10 = ServerOptions.instance.RCONPort.getValue();
            String string20 = ServerOptions.instance.RCONPassword.getValue();
            if (int10 != 0 && string20 != null && !string20.isEmpty()) {
                String string21 = System.getProperty("rconlo");
                RCONServer.init(int10, string20, string21 != null);
            }

            LuaManager.GlobalObject.refreshAnimSets(true);

            while (!bDone) {
                try {
                    long long2 = System.nanoTime();
                    MPStatistics.countServerNetworkingFPS();
                    MainLoopNetData2.clear();

                    for (IZomboidPacket iZomboidPacket0 = (IZomboidPacket)MainLoopNetDataHighPriorityQ.poll();
                        iZomboidPacket0 != null;
                        iZomboidPacket0 = (IZomboidPacket)MainLoopNetDataHighPriorityQ.poll()
                    ) {
                        MainLoopNetData2.add(iZomboidPacket0);
                    }

                    MPStatistic.getInstance().setPacketsLength((long)MainLoopNetData2.size());

                    for (int int11 = 0; int11 < MainLoopNetData2.size(); int11++) {
                        IZomboidPacket iZomboidPacket1 = (IZomboidPacket)MainLoopNetData2.get(int11);
                        if (iZomboidPacket1.isConnect()) {
                            UdpConnection udpConnection0 = ((GameServer.DelayedConnection)iZomboidPacket1).connection;
                            LoggerManager.getLogger("user")
                                .write("added connection index=" + udpConnection0.index + " " + ((GameServer.DelayedConnection)iZomboidPacket1).hostString);
                            udpEngine.connections.add(udpConnection0);
                        } else if (iZomboidPacket1.isDisconnect()) {
                            UdpConnection udpConnection1 = ((GameServer.DelayedConnection)iZomboidPacket1).connection;
                            LoginQueue.disconnect(udpConnection1);
                            LoggerManager.getLogger("user")
                                .write(udpConnection1.idStr + " \"" + udpConnection1.username + "\" removed connection index=" + udpConnection1.index);
                            udpEngine.connections.remove(udpConnection1);
                            disconnect(udpConnection1, "receive-disconnect");
                        } else {
                            mainLoopDealWithNetData((ZomboidNetData)iZomboidPacket1);
                        }
                    }

                    MainLoopPlayerUpdate.clear();

                    for (IZomboidPacket iZomboidPacket2 = (IZomboidPacket)MainLoopPlayerUpdateQ.poll();
                        iZomboidPacket2 != null;
                        iZomboidPacket2 = (IZomboidPacket)MainLoopPlayerUpdateQ.poll()
                    ) {
                        ZomboidNetData zomboidNetData0 = (ZomboidNetData)iZomboidPacket2;
                        long long3 = zomboidNetData0.connection * 4L + (long)zomboidNetData0.buffer.getShort(0);
                        ZomboidNetData zomboidNetData1 = (ZomboidNetData)MainLoopPlayerUpdate.put(long3, zomboidNetData0);
                        if (zomboidNetData1 != null) {
                            ZomboidNetDataPool.instance.discard(zomboidNetData1);
                        }
                    }

                    MainLoopNetData2.clear();
                    MainLoopNetData2.addAll(MainLoopPlayerUpdate.values());
                    MainLoopPlayerUpdate.clear();
                    MPStatistic.getInstance().setPacketsLength((long)MainLoopNetData2.size());

                    for (int int12 = 0; int12 < MainLoopNetData2.size(); int12++) {
                        IZomboidPacket iZomboidPacket3 = (IZomboidPacket)MainLoopNetData2.get(int12);
                        GameServer.s_performance.mainLoopDealWithNetData.invokeAndMeasure((ZomboidNetData)iZomboidPacket3, GameServer::mainLoopDealWithNetData);
                    }

                    MainLoopNetData2.clear();

                    for (IZomboidPacket iZomboidPacket4 = (IZomboidPacket)MainLoopNetDataQ.poll();
                        iZomboidPacket4 != null;
                        iZomboidPacket4 = (IZomboidPacket)MainLoopNetDataQ.poll()
                    ) {
                        MainLoopNetData2.add(iZomboidPacket4);
                    }

                    for (int int13 = 0; int13 < MainLoopNetData2.size(); int13++) {
                        if (int13 % 10 == 0 && (System.nanoTime() - long2) / 1000000L > 70L) {
                            if (droppedPackets == 0) {
                                DebugLog.log("Server is too busy. Server will drop updates of vehicle's physics. Server is closed for new connections.");
                            }

                            droppedPackets += 2;
                            countOfDroppedPackets = countOfDroppedPackets + (MainLoopNetData2.size() - int13);
                            break;
                        }

                        IZomboidPacket iZomboidPacket5 = (IZomboidPacket)MainLoopNetData2.get(int13);
                        GameServer.s_performance.mainLoopDealWithNetData.invokeAndMeasure((ZomboidNetData)iZomboidPacket5, GameServer::mainLoopDealWithNetData);
                    }

                    MainLoopNetData2.clear();
                    if (droppedPackets == 1) {
                        DebugLog.log(
                            "Server is working normal. Server will not drop updates of vehicle's physics. The server is open for new connections. Server dropped "
                                + countOfDroppedPackets
                                + " packets and "
                                + countOfDroppedConnections
                                + " connections."
                        );
                        countOfDroppedPackets = 0;
                        countOfDroppedConnections = 0;
                    }

                    droppedPackets = Math.max(0, Math.min(1000, droppedPackets - 1));
                    if (!updateLimit.Check()) {
                        long long4 = PZMath.clamp((5000000L - System.nanoTime() + long2) / 1000000L, 0L, 100L);
                        if (long4 > 0L) {
                            try {
                                MPStatistic.getInstance().Main.StartSleep();
                                Thread.sleep(long4);
                                MPStatistic.getInstance().Main.EndSleep();
                            } catch (InterruptedException interruptedException1) {
                                interruptedException1.printStackTrace();
                            }
                        }
                    } else {
                        MPStatistic.getInstance().Main.Start();
                        IsoCamera.frameState.frameCount++;
                        GameServer.s_performance.frameStep.start();

                        try {
                            timeSinceKeepAlive = timeSinceKeepAlive + zombie.GameTime.getInstance().getMultiplier();
                            MPStatistic.getInstance().ServerMapPreupdate.Start();
                            ServerMap.instance.preupdate();
                            MPStatistic.getInstance().ServerMapPreupdate.End();
                            synchronized (consoleCommands) {
                                for (int int14 = 0; int14 < consoleCommands.size(); int14++) {
                                    String string22 = (String)consoleCommands.get(int14);

                                    try {
                                        if (CoopSlave.instance == null || !CoopSlave.instance.handleCommand(string22)) {
                                            System.out.println(handleServerCommand(string22, null));
                                        }
                                    } catch (Exception exception4) {
                                        exception4.printStackTrace();
                                    }
                                }

                                consoleCommands.clear();
                            }

                            if (removeZombiesConnection != null) {
                                NetworkZombieManager.removeZombies(removeZombiesConnection);
                                removeZombiesConnection = null;
                            }

                            GameServer.s_performance.RCONServerUpdate.invokeAndMeasure(RCONServer::update);

                            try {
                                zombie.MapCollisionData.instance.updateGameState();
                                MPStatistic.getInstance().IngameStateUpdate.Start();
                                ingameState.update();
                                MPStatistic.getInstance().IngameStateUpdate.End();
                                VehicleManager.instance.serverUpdate();
                            } catch (Exception exception5) {
                                exception5.printStackTrace();
                            }

                            int int15 = 0;
                            int int16 = 0;

                            for (int int17 = 0; int17 < Players.size(); int17++) {
                                IsoPlayer isoPlayer = (IsoPlayer)Players.get(int17);
                                if (isoPlayer.isAlive()) {
                                    if (!IsoWorld.instance.CurrentCell.getObjectList().contains(isoPlayer)) {
                                        IsoWorld.instance.CurrentCell.getObjectList().add(isoPlayer);
                                    }

                                    int16++;
                                    if (isoPlayer.isAsleep()) {
                                        int15++;
                                    }
                                }

                                ServerMap.instance.characterIn(isoPlayer);
                            }

                            setFastForward(ServerOptions.instance.SleepAllowed.getValue() && int16 > 0 && int15 == int16);
                            boolean boolean1 = calcCountPlayersInRelevantPositionLimiter.Check();

                            for (int int18 = 0; int18 < udpEngine.connections.size(); int18++) {
                                UdpConnection udpConnection2 = (UdpConnection)udpEngine.connections.get(int18);
                                if (boolean1) {
                                    udpConnection2.calcCountPlayersInRelevantPosition();
                                }

                                for (int int19 = 0; int19 < 4; int19++) {
                                    Vector3 vector3 = udpConnection2.connectArea[int19];
                                    if (vector3 != null) {
                                        ServerMap.instance.characterIn((int)vector3.x, (int)vector3.y, (int)vector3.z);
                                    }

                                    ClientServerMap.characterIn(udpConnection2, int19);
                                }

                                if (udpConnection2.playerDownloadServer != null) {
                                    udpConnection2.playerDownloadServer.update();
                                }
                            }

                            for (int int20 = 0; int20 < IsoWorld.instance.CurrentCell.getObjectList().size(); int20++) {
                                IsoMovingObject isoMovingObject = (IsoMovingObject)IsoWorld.instance.CurrentCell.getObjectList().get(int20);
                                if (isoMovingObject instanceof IsoPlayer && !Players.contains(isoMovingObject)) {
                                    DebugLog.log("Disconnected player in CurrentCell.getObjectList() removed");
                                    IsoWorld.instance.CurrentCell.getObjectList().remove(int20--);
                                }
                            }

                            if (++int6 > 150) {
                                for (int int21 = 0; int21 < udpEngine.connections.size(); int21++) {
                                    UdpConnection udpConnection3 = (UdpConnection)udpEngine.connections.get(int21);

                                    try {
                                        if (udpConnection3.username == null
                                            && !udpConnection3.awaitingCoopApprove
                                            && !LoginQueue.isInTheQueue(udpConnection3)
                                            && udpConnection3.isConnectionAttemptTimeout()) {
                                            disconnect(udpConnection3, "connection-attempt-timeout");
                                            udpEngine.forceDisconnect(udpConnection3.getConnectedGUID(), "connection-attempt-timeout");
                                        }
                                    } catch (Exception exception6) {
                                        exception6.printStackTrace();
                                    }
                                }

                                int6 = 0;
                            }

                            worldObjectsServerSyncReq.serverSendRequests(udpEngine);
                            MPStatistic.getInstance().ServerMapPostupdate.Start();
                            ServerMap.instance.postupdate();
                            MPStatistic.getInstance().ServerMapPostupdate.End();

                            try {
                                ServerGUI.update();
                            } catch (Exception exception7) {
                                exception7.printStackTrace();
                            }

                            long1 = long0;
                            long0 = System.currentTimeMillis();
                            long long5 = long0 - long1;
                            float0 = 1000.0F / (float)long5;
                            if (!Float.isNaN(float0)) {
                                float2 = (float)((double)float2 + Math.min((double)(float0 - float2) * 0.05, 1.0));
                            }

                            zombie.GameTime.instance.FPSMultiplier = 60.0F / float2;
                            launchCommandHandler();
                            MPStatistic.getInstance().process(long5);
                            if (!SteamUtils.isSteamModeEnabled()) {
                                PublicServerUtil.update();
                                PublicServerUtil.updatePlayerCountIfChanged();
                            }

                            for (int int22 = 0; int22 < udpEngine.connections.size(); int22++) {
                                UdpConnection udpConnection4 = (UdpConnection)udpEngine.connections.get(int22);
                                if (udpConnection4.checksumState == UdpConnection.ChecksumState.Different
                                    && udpConnection4.checksumTime + 8000L < System.currentTimeMillis()) {
                                    DebugLog.log("timed out connection because checksum was different");
                                    udpConnection4.checksumState = UdpConnection.ChecksumState.Init;
                                    udpConnection4.forceDisconnect("checksum-timeout");
                                } else {
                                    udpConnection4.validator.update();
                                    if (!udpConnection4.chunkObjectState.isEmpty()) {
                                        for (byte _byte = 0; _byte < udpConnection4.chunkObjectState.size(); _byte += 2) {
                                            short short0 = udpConnection4.chunkObjectState.get(_byte);
                                            short short1 = udpConnection4.chunkObjectState.get(_byte + 1);
                                            if (!udpConnection4.RelevantTo(
                                                (float)(short0 * 10 + 5), (float)(short1 * 10 + 5), (float)(udpConnection4.ChunkGridWidth * 4 * 10)
                                            )) {
                                                udpConnection4.chunkObjectState.remove(_byte, 2);
                                                _byte -= 2;
                                            }
                                        }
                                    }
                                }
                            }

                            if (sendWorldMapPlayerPositionLimiter.Check()) {
                                try {
                                    sendWorldMapPlayerPosition();
                                } catch (Exception exception8) {
                                    boolean boolean2 = true;
                                }
                            }

                            if (CoopSlave.instance != null) {
                                CoopSlave.instance.update();
                                if (CoopSlave.instance.masterLost()) {
                                    DebugLog.log("Coop master is not responding, terminating");
                                    ServerMap.instance.QueueQuit();
                                }
                            }

                            LoginQueue.update();
                            ZipBackup.onPeriod();
                            SteamUtils.runLoop();
                            zombie.GameWindow.fileSystem.updateAsyncTransactions();
                        } catch (Exception exception9) {
                            if (mainCycleExceptionLogCount-- > 0) {
                                DebugLog.Multiplayer.printException(exception9, "Server processing error", LogSeverity.Error);
                            }
                        } finally {
                            GameServer.s_performance.frameStep.end();
                        }
                    }
                } catch (Exception exception10) {
                    if (mainCycleExceptionLogCount-- > 0) {
                        DebugLog.Multiplayer.printException(exception10, "Server error", LogSeverity.Error);
                    }
                }
            }

            CoopSlave.status("UI_ServerStatus_Terminated");
            DebugLog.log(DebugType.Network, "Server exited");
            ServerGUI.shutdown();
            ServerPlayerDB.getInstance().close();
            VehiclesDB2.instance.Reset();
            SteamUtils.shutdown();
            System.exit(0);
        }
    }

    private static void launchCommandHandler() {
        if (!launched) {
            launched = true;
            new Thread(ThreadGroups.Workers, () -> {
                try {
                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

                    while (true) {
                        String string = bufferedReader.readLine();
                        if (string == null) {
                            consoleCommands.add("process-status@eof");
                            break;
                        }

                        if (!string.isEmpty()) {
                            System.out.println("command entered via server console (System.in): \"" + string + "\"");
                            synchronized (consoleCommands) {
                                consoleCommands.add(string);
                            }
                        }
                    }
                } catch (Exception exception) {
                    exception.printStackTrace();
                }
            }, "command handler").start();
        }
    }

    public static String rcon(String command) {
        try {
            return handleServerCommand(command, null);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            return null;
        }
    }

    private static String handleServerCommand(String string0, UdpConnection udpConnection) {
        if (string0 == null) {
            return null;
        } else {
            String string1 = "admin";
            String string2 = "admin";
            if (udpConnection != null) {
                string1 = udpConnection.username;
                string2 = PlayerType.toString(udpConnection.accessLevel);
            }

            if (udpConnection != null && udpConnection.isCoopHost) {
                string2 = "admin";
            }

            Class _class = CommandBase.findCommandCls(string0);
            if (_class != null) {
                Constructor constructor = _class.getConstructors()[0];

                try {
                    CommandBase commandBase = (CommandBase)constructor.newInstance(string1, string2, string0, udpConnection);
                    return commandBase.Execute();
                } catch (InvocationTargetException invocationTargetException) {
                    invocationTargetException.printStackTrace();
                    return "A InvocationTargetException error occured";
                } catch (IllegalAccessException illegalAccessException) {
                    illegalAccessException.printStackTrace();
                    return "A IllegalAccessException error occured";
                } catch (InstantiationException instantiationException) {
                    instantiationException.printStackTrace();
                    return "A InstantiationException error occured";
                } catch (SQLException sQLException) {
                    sQLException.printStackTrace();
                    return "A SQL error occured";
                }
            } else {
                return "Unknown command " + string0;
            }
        }
    }

    public static void sendTeleport(IsoPlayer player, float x, float y, float z) {
        UdpConnection udpConnection = getConnectionFromPlayer(player);
        if (udpConnection == null) {
            DebugLog.log("No connection found for user " + player.getUsername());
        } else {
            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
            PacketTypes.PacketType.Teleport.doPacket(byteBufferWriter);
            byteBufferWriter.putByte((byte)0);
            byteBufferWriter.putFloat(x);
            byteBufferWriter.putFloat(y);
            byteBufferWriter.putFloat(z);
            PacketTypes.PacketType.Teleport.send(udpConnection);
            if (udpConnection.players[0] != null && udpConnection.players[0].getNetworkCharacterAI() != null) {
                udpConnection.players[0].getNetworkCharacterAI().resetSpeedLimiter();
            }
        }
    }

    static void receiveTeleport(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        String string = zombie.GameWindow.ReadString(byteBuffer);
        float float0 = byteBuffer.getFloat();
        float float1 = byteBuffer.getFloat();
        float float2 = byteBuffer.getFloat();
        IsoPlayer isoPlayer = getPlayerByRealUserName(string);
        if (isoPlayer != null) {
            UdpConnection udpConnection = getConnectionFromPlayer(isoPlayer);
            if (udpConnection != null) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.Teleport.doPacket(byteBufferWriter);
                byteBufferWriter.putByte((byte)isoPlayer.PlayerIndex);
                byteBufferWriter.putFloat(float0);
                byteBufferWriter.putFloat(float1);
                byteBufferWriter.putFloat(float2);
                PacketTypes.PacketType.Teleport.send(udpConnection);
                if (isoPlayer.getNetworkCharacterAI() != null) {
                    isoPlayer.getNetworkCharacterAI().resetSpeedLimiter();
                }

                if (isoPlayer.isAsleep()) {
                    isoPlayer.setAsleep(false);
                    isoPlayer.setAsleepTime(0.0F);
                    sendWakeUpPlayer(isoPlayer, null);
                }
            }
        }
    }

    public static void sendPlayerExtraInfo(IsoPlayer p, UdpConnection connection) {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
            PacketTypes.PacketType.ExtraInfo.doPacket(byteBufferWriter);
            byteBufferWriter.putShort(p.OnlineID);
            byteBufferWriter.putUTF(p.accessLevel);
            byteBufferWriter.putByte((byte)(p.isGodMod() ? 1 : 0));
            byteBufferWriter.putByte((byte)(p.isGhostMode() ? 1 : 0));
            byteBufferWriter.putByte((byte)(p.isInvisible() ? 1 : 0));
            byteBufferWriter.putByte((byte)(p.isNoClip() ? 1 : 0));
            byteBufferWriter.putByte((byte)(p.isShowAdminTag() ? 1 : 0));
            PacketTypes.PacketType.ExtraInfo.send(udpConnection);
        }
    }

    static void receiveExtraInfo(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        short _short = byteBuffer.getShort();
        boolean boolean0 = byteBuffer.get() == 1;
        boolean boolean1 = byteBuffer.get() == 1;
        boolean boolean2 = byteBuffer.get() == 1;
        boolean boolean3 = byteBuffer.get() == 1;
        boolean boolean4 = byteBuffer.get() == 1;
        boolean boolean5 = byteBuffer.get() == 1;
        IsoPlayer isoPlayer = getPlayerFromConnection(udpConnection, _short);
        if (isoPlayer != null) {
            isoPlayer.setGodMod(boolean0);
            isoPlayer.setGhostMode(boolean1);
            isoPlayer.setInvisible(boolean2);
            isoPlayer.setNoClip(boolean3);
            isoPlayer.setShowAdminTag(boolean4);
            isoPlayer.setCanHearAll(boolean5);
            sendPlayerExtraInfo(isoPlayer, udpConnection);
        }
    }

    static void receiveAddXp(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        AddXp addXp = new AddXp();
        addXp.parse(byteBuffer, udpConnection0);
        if (addXp.isConsistent() && addXp.validate(udpConnection0)) {
            if (!canModifyPlayerStats(udpConnection0, addXp.target.getCharacter())) {
                PacketTypes.PacketType.AddXP.onUnauthorized(udpConnection0);
            } else {
                addXp.process();
                if (canModifyPlayerStats(udpConnection0, null)) {
                    addXp.target.getCharacter().getXp().recalcSumm();
                }

                for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                    UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
                    if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()
                        && udpConnection1.getConnectedGUID() == (Long)PlayerToAddressMap.get(addXp.target.getCharacter())) {
                        ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                        PacketTypes.PacketType.AddXP.doPacket(byteBufferWriter);
                        addXp.write(byteBufferWriter);
                        PacketTypes.PacketType.AddXP.send(udpConnection1);
                    }
                }
            }
        }
    }

    private static boolean canSeePlayerStats(UdpConnection udpConnection) {
        return udpConnection.accessLevel != 1;
    }

    private static boolean canModifyPlayerStats(UdpConnection udpConnection, IsoPlayer isoPlayer) {
        return (udpConnection.accessLevel & 56) != 0 || udpConnection.havePlayer(isoPlayer);
    }

    static void receiveSyncXP(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        IsoPlayer isoPlayer = (IsoPlayer)IDToPlayerMap.get(byteBuffer.getShort());
        if (isoPlayer != null) {
            if (!canModifyPlayerStats(udpConnection0, isoPlayer)) {
                PacketTypes.PacketType.SyncXP.onUnauthorized(udpConnection0);
            } else {
                if (isoPlayer != null && !isoPlayer.isDead()) {
                    try {
                        isoPlayer.getXp().load(byteBuffer, 195);
                    } catch (IOException iOException0) {
                        iOException0.printStackTrace();
                    }

                    for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                        UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
                        if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()) {
                            ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                            PacketTypes.PacketType.SyncXP.doPacket(byteBufferWriter);
                            byteBufferWriter.putShort(isoPlayer.getOnlineID());

                            try {
                                isoPlayer.getXp().save(byteBufferWriter.bb);
                            } catch (IOException iOException1) {
                                iOException1.printStackTrace();
                            }

                            PacketTypes.PacketType.SyncXP.send(udpConnection1);
                        }
                    }
                }
            }
        }
    }

    static void receiveChangePlayerStats(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        short _short = byteBuffer.getShort();
        IsoPlayer isoPlayer = (IsoPlayer)IDToPlayerMap.get(_short);
        if (isoPlayer != null) {
            String string = zombie.GameWindow.ReadString(byteBuffer);
            isoPlayer.setPlayerStats(byteBuffer, string);

            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID()) {
                    if (udpConnection0.getConnectedGUID() == (Long)PlayerToAddressMap.get(isoPlayer)) {
                        udpConnection0.allChatMuted = isoPlayer.isAllChatMuted();
                        udpConnection0.accessLevel = PlayerType.fromString(isoPlayer.accessLevel);
                    }

                    ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                    PacketTypes.PacketType.ChangePlayerStats.doPacket(byteBufferWriter);
                    isoPlayer.createPlayerStats(byteBufferWriter, string);
                    PacketTypes.PacketType.ChangePlayerStats.send(udpConnection0);
                }
            }
        }
    }

    public static void doMinimumInit() throws IOException {
        Rand.init();
        zombie.DebugFileWatcher.instance.init();
        ArrayList arrayList = new ArrayList(ServerMods);
        zombie.ZomboidFileSystem.instance.loadMods(arrayList);
        LuaManager.init();
        PerkFactory.init();
        CustomPerks.instance.init();
        CustomPerks.instance.initLua();
        AssetManagers assetManagers = zombie.GameWindow.assetManagers;
        AiSceneAssetManager.instance.create(AiSceneAsset.ASSET_TYPE, assetManagers);
        AnimationAssetManager.instance.create(AnimationAsset.ASSET_TYPE, assetManagers);
        AnimNodeAssetManager.instance.create(AnimationAsset.ASSET_TYPE, assetManagers);
        ClothingItemAssetManager.instance.create(ClothingItem.ASSET_TYPE, assetManagers);
        MeshAssetManager.instance.create(ModelMesh.ASSET_TYPE, assetManagers);
        ModelAssetManager.instance.create(Model.ASSET_TYPE, assetManagers);
        TextureIDAssetManager.instance.create(TextureID.ASSET_TYPE, assetManagers);
        TextureAssetManager.instance.create(Texture.ASSET_TYPE, assetManagers);
        if (GUICommandline && !bSoftReset) {
            ServerGUI.init();
        }

        CustomSandboxOptions.instance.init();
        CustomSandboxOptions.instance.initInstance(zombie.SandboxOptions.instance);
        ScriptManager.instance.Load();
        ClothingDecals.init();
        BeardStyles.init();
        HairStyles.init();
        OutfitManager.init();
        if (!bSoftReset) {
            JAssImpImporter.Init();
            ModelManager.NoOpenGL = !ServerGUI.isCreated();
            ModelManager.instance.create();
            System.out.println("LOADING ASSETS: START");

            while (zombie.GameWindow.fileSystem.hasWork()) {
                zombie.GameWindow.fileSystem.updateAsyncTransactions();
            }

            System.out.println("LOADING ASSETS: FINISH");
        }

        try {
            LuaManager.initChecksum();
            LuaManager.LoadDirBase("shared");
            LuaManager.LoadDirBase("client", true);
            LuaManager.LoadDirBase("server");
            LuaManager.finishChecksum();
        } catch (Exception exception) {
            exception.printStackTrace();
        }

        RecipeManager.LoadedAfterLua();
        File file = new File(zombie.ZomboidFileSystem.instance.getCacheDir() + File.separator + "Server" + File.separator + ServerName + "_SandboxVars.lua");
        if (file.exists()) {
            if (!zombie.SandboxOptions.instance.loadServerLuaFile(ServerName)) {
                System.out.println("Exiting due to errors loading " + file.getCanonicalPath());
                System.exit(1);
            }

            zombie.SandboxOptions.instance.handleOldServerZombiesFile();
            zombie.SandboxOptions.instance.saveServerLuaFile(ServerName);
            zombie.SandboxOptions.instance.toLua();
        } else {
            zombie.SandboxOptions.instance.handleOldServerZombiesFile();
            zombie.SandboxOptions.instance.saveServerLuaFile(ServerName);
            zombie.SandboxOptions.instance.toLua();
        }

        LuaEventManager.triggerEvent("OnGameBoot");
        zombie.ZomboidGlobals.Load();
        SpawnPoints.instance.initServer1();
        ServerGUI.init2();
    }

    public static void startServer() throws ConnectException {
        String string0 = ServerOptions.instance.Password.getValue();
        if (CoopSlave.instance != null && SteamUtils.isSteamModeEnabled()) {
            string0 = "";
        }

        udpEngine = new UdpEngine(DEFAULT_PORT, UDPPort, ServerOptions.getInstance().getMaxPlayers(), string0, true);
        DebugLog.log(DebugType.Network, "*** SERVER STARTED ****");
        DebugLog.log(DebugType.Network, "*** Steam is " + (SteamUtils.isSteamModeEnabled() ? "enabled" : "not enabled"));
        if (SteamUtils.isSteamModeEnabled()) {
            DebugLog.log(
                DebugType.Network,
                "Server is listening on port " + DEFAULT_PORT + " (for Steam connection) and port " + UDPPort + " (for UDPRakNet connection)"
            );
            DebugLog.log(DebugType.Network, "Clients should use " + DEFAULT_PORT + " port for connections");
        } else {
            DebugLog.log(DebugType.Network, "server is listening on port " + DEFAULT_PORT);
        }

        ResetID = ServerOptions.instance.ResetID.getValue();
        if (CoopSlave.instance != null) {
            if (SteamUtils.isSteamModeEnabled()) {
                RakNetPeerInterface rakNetPeerInterface = udpEngine.getPeer();
                CoopSlave.instance.sendMessage("server-address", null, rakNetPeerInterface.GetServerIP() + ":" + DEFAULT_PORT);
                long _long = SteamGameServer.GetSteamID();
                CoopSlave.instance.sendMessage("steam-id", null, SteamUtils.convertSteamIDToString(_long));
            } else {
                String string1 = "127.0.0.1";
                CoopSlave.instance.sendMessage("server-address", null, string1 + ":" + DEFAULT_PORT);
            }
        }

        LuaEventManager.triggerEvent("OnServerStarted");
        if (SteamUtils.isSteamModeEnabled()) {
            CoopSlave.status("UI_ServerStatus_Started");
        } else {
            CoopSlave.status("UI_ServerStatus_Started");
        }

        String string2 = ServerOptions.instance.DiscordChannel.getValue();
        String string3 = ServerOptions.instance.DiscordToken.getValue();
        boolean _boolean = ServerOptions.instance.DiscordEnable.getValue();
        String string4 = ServerOptions.instance.DiscordChannelID.getValue();
        discordBot.connect(_boolean, string3, string2, string4);
    }

    private static void mainLoopDealWithNetData(ZomboidNetData zomboidNetData) {
        if (zombie.SystemDisabler.getDoMainLoopDealWithNetData()) {
            ByteBuffer byteBuffer = zomboidNetData.buffer;
            UdpConnection udpConnection = udpEngine.getActiveConnection(zomboidNetData.connection);
            if (zomboidNetData.type == null) {
                ZomboidNetDataPool.instance.discard(zomboidNetData);
            } else {
                zomboidNetData.type.serverPacketCount++;
                MPStatistic.getInstance().addIncomePacket(zomboidNetData.type, byteBuffer.limit());

                try {
                    if (udpConnection == null) {
                        DebugLog.log(DebugType.Network, "Received packet type=" + zomboidNetData.type.name() + " connection is null.");
                        return;
                    }

                    if (udpConnection.username == null) {
                        switch (zomboidNetData.type) {
                            case Login:
                            case Ping:
                            case ScoreboardUpdate:
                                break;
                            default:
                                DebugLog.log(
                                    "Received packet type="
                                        + zomboidNetData.type.name()
                                        + " before Login, disconnecting "
                                        + udpConnection.getInetSocketAddress().getHostString()
                                );
                                udpConnection.forceDisconnect("unacceptable-packet");
                                ZomboidNetDataPool.instance.discard(zomboidNetData);
                                return;
                        }
                    }

                    zomboidNetData.type.onServerPacket(byteBuffer, udpConnection);
                } catch (Exception exception) {
                    if (udpConnection == null) {
                        DebugLog.log(DebugType.Network, "Error with packet of type: " + zomboidNetData.type + " connection is null.");
                    } else {
                        DebugLog.General.error("Error with packet of type: " + zomboidNetData.type + " for " + udpConnection.username);
                    }

                    exception.printStackTrace();
                }

                ZomboidNetDataPool.instance.discard(zomboidNetData);
            }
        }
    }

    static void receiveInvMngRemoveItem(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        int int0 = byteBuffer.getInt();
        short _short = byteBuffer.getShort();
        IsoPlayer isoPlayer = (IsoPlayer)IDToPlayerMap.get(_short);
        if (isoPlayer != null) {
            for (int int1 = 0; int1 < udpEngine.connections.size(); int1++) {
                UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int1);
                if (udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID()
                    && udpConnection0.getConnectedGUID() == (Long)PlayerToAddressMap.get(isoPlayer)) {
                    ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                    PacketTypes.PacketType.InvMngRemoveItem.doPacket(byteBufferWriter);
                    byteBufferWriter.putInt(int0);
                    PacketTypes.PacketType.InvMngRemoveItem.send(udpConnection0);
                    break;
                }
            }
        }
    }

    static void receiveInvMngGetItem(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) throws IOException {
        short _short = byteBuffer.getShort();
        IsoPlayer isoPlayer = (IsoPlayer)IDToPlayerMap.get(_short);
        if (isoPlayer != null) {
            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID()
                    && udpConnection0.getConnectedGUID() == (Long)PlayerToAddressMap.get(isoPlayer)) {
                    ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                    PacketTypes.PacketType.InvMngGetItem.doPacket(byteBufferWriter);
                    byteBuffer.rewind();
                    byteBufferWriter.bb.put(byteBuffer);
                    PacketTypes.PacketType.InvMngGetItem.send(udpConnection0);
                    break;
                }
            }
        }
    }

    static void receiveInvMngReqItem(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        int int0 = 0;
        String string = null;
        if (byteBuffer.get() == 1) {
            string = zombie.GameWindow.ReadString(byteBuffer);
        } else {
            int0 = byteBuffer.getInt();
        }

        short short0 = byteBuffer.getShort();
        short short1 = byteBuffer.getShort();
        IsoPlayer isoPlayer = (IsoPlayer)IDToPlayerMap.get(short1);
        if (isoPlayer != null) {
            for (int int1 = 0; int1 < udpEngine.connections.size(); int1++) {
                UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int1);
                if (udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID()
                    && udpConnection0.getConnectedGUID() == (Long)PlayerToAddressMap.get(isoPlayer)) {
                    ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                    PacketTypes.PacketType.InvMngReqItem.doPacket(byteBufferWriter);
                    if (string != null) {
                        byteBufferWriter.putByte((byte)1);
                        byteBufferWriter.putUTF(string);
                    } else {
                        byteBufferWriter.putByte((byte)0);
                        byteBufferWriter.putInt(int0);
                    }

                    byteBufferWriter.putShort(short0);
                    PacketTypes.PacketType.InvMngReqItem.send(udpConnection0);
                    break;
                }
            }
        }
    }

    static void receiveRequestZipList(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) throws Exception {
        if (!udpConnection.wasInLoadingQueue) {
            kick(udpConnection, "UI_Policy_Kick", "The server received an invalid request");
        }

        if (udpConnection.playerDownloadServer != null) {
            udpConnection.playerDownloadServer.receiveRequestArray(byteBuffer);
        }
    }

    static void receiveRequestLargeAreaZip(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        if (!udpConnection.wasInLoadingQueue) {
            kick(udpConnection, "UI_Policy_Kick", "The server received an invalid request");
        }

        if (udpConnection.playerDownloadServer != null) {
            int int0 = byteBuffer.getInt();
            int int1 = byteBuffer.getInt();
            int int2 = byteBuffer.getInt();
            udpConnection.connectArea[0] = new Vector3((float)int0, (float)int1, (float)int2);
            udpConnection.ChunkGridWidth = int2;
            ZombiePopulationManager.instance.updateLoadedAreas();
        }
    }

    static void receiveNotRequiredInZip(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        if (udpConnection.playerDownloadServer != null) {
            udpConnection.playerDownloadServer.receiveCancelRequest(byteBuffer);
        }
    }

    static void receiveLogin(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        ConnectionManager.log("receive-packet", "login", udpConnection0);
        String string0 = zombie.GameWindow.ReadString(byteBuffer).trim();
        String string1 = zombie.GameWindow.ReadString(byteBuffer).trim();
        String string2 = zombie.GameWindow.ReadString(byteBuffer).trim();
        if (!string2.equals(Core.getInstance().getVersion())) {
            ByteBufferWriter byteBufferWriter0 = udpConnection0.startPacket();
            PacketTypes.PacketType.AccessDenied.doPacket(byteBufferWriter0);
            LoggerManager.getLogger("user")
                .write(
                    "access denied: user \""
                        + string0
                        + "\" client version ("
                        + string2
                        + ") does not match server version ("
                        + Core.getInstance().getVersion()
                        + ")"
                );
            byteBufferWriter0.putUTF("ClientVersionMismatch##" + string2 + "##" + Core.getInstance().getVersion());
            PacketTypes.PacketType.AccessDenied.send(udpConnection0);
            ConnectionManager.log("access-denied", "version-mismatch", udpConnection0);
            udpConnection0.forceDisconnect("access-denied-client-version");
        }

        udpConnection0.wasInLoadingQueue = false;
        udpConnection0.ip = udpConnection0.getInetSocketAddress().getHostString();
        udpConnection0.validator.reset();
        udpConnection0.idStr = udpConnection0.ip;
        if (SteamUtils.isSteamModeEnabled()) {
            udpConnection0.steamID = udpEngine.getClientSteamID(udpConnection0.getConnectedGUID());
            if (udpConnection0.steamID == -1L) {
                ByteBufferWriter byteBufferWriter1 = udpConnection0.startPacket();
                PacketTypes.PacketType.AccessDenied.doPacket(byteBufferWriter1);
                LoggerManager.getLogger("user")
                    .write("access denied: The client \"" + string0 + "\" did not complete the connection and authorization procedure in zombienet");
                byteBufferWriter1.putUTF("ClientIsNofFullyConnectedInZombienet");
                PacketTypes.PacketType.AccessDenied.send(udpConnection0);
                ConnectionManager.log("access-denied", "znet-error", udpConnection0);
                udpConnection0.forceDisconnect("access-denied-zombienet-connect");
            }

            udpConnection0.ownerID = udpEngine.getClientOwnerSteamID(udpConnection0.getConnectedGUID());
            udpConnection0.idStr = SteamUtils.convertSteamIDToString(udpConnection0.steamID);
            if (udpConnection0.steamID != udpConnection0.ownerID) {
                udpConnection0.idStr = udpConnection0.idStr + "(owner=" + SteamUtils.convertSteamIDToString(udpConnection0.ownerID) + ")";
            }
        }

        udpConnection0.password = string1;
        LoggerManager.getLogger("user").write(udpConnection0.idStr + " \"" + string0 + "\" attempting to join");
        if (CoopSlave.instance != null && SteamUtils.isSteamModeEnabled()) {
            for (int int0 = 0; int0 < udpEngine.connections.size(); int0++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(int0);
                if (udpConnection1 != udpConnection0 && udpConnection1.steamID == udpConnection0.steamID) {
                    LoggerManager.getLogger("user").write("access denied: user \"" + string0 + "\" already connected");
                    ByteBufferWriter byteBufferWriter2 = udpConnection0.startPacket();
                    PacketTypes.PacketType.AccessDenied.doPacket(byteBufferWriter2);
                    byteBufferWriter2.putUTF("AlreadyConnected");
                    PacketTypes.PacketType.AccessDenied.send(udpConnection0);
                    ConnectionManager.log("access-denied", "already-connected-steamid", udpConnection0);
                    udpConnection0.forceDisconnect("access-denied-already-connected-cs");
                    return;
                }
            }

            udpConnection0.username = string0;
            udpConnection0.usernames[0] = string0;
            udpConnection0.isCoopHost = udpEngine.connections.size() == 1;
            DebugLog.Multiplayer.debugln(udpConnection0.idStr + " isCoopHost=" + udpConnection0.isCoopHost);
            udpConnection0.accessLevel = 1;
            if (!ServerOptions.instance.DoLuaChecksum.getValue()) {
                udpConnection0.checksumState = UdpConnection.ChecksumState.Done;
            }

            if (getPlayerCount() >= ServerOptions.getInstance().getMaxPlayers()) {
                ByteBufferWriter byteBufferWriter3 = udpConnection0.startPacket();
                PacketTypes.PacketType.AccessDenied.doPacket(byteBufferWriter3);
                byteBufferWriter3.putUTF("ServerFull");
                PacketTypes.PacketType.AccessDenied.send(udpConnection0);
                ConnectionManager.log("access-denied", "server-full", udpConnection0);
                udpConnection0.forceDisconnect("access-denied-server-full-cs");
            } else {
                if (isServerDropPackets() && ServerOptions.instance.DenyLoginOnOverloadedServer.getValue()) {
                    ByteBufferWriter byteBufferWriter4 = udpConnection0.startPacket();
                    PacketTypes.PacketType.AccessDenied.doPacket(byteBufferWriter4);
                    LoggerManager.getLogger("user").write("access denied: user \"" + string0 + "\" Server is too busy");
                    byteBufferWriter4.putUTF("Server is too busy.");
                    PacketTypes.PacketType.AccessDenied.send(udpConnection0);
                    ConnectionManager.log("access-denied", "server-busy", udpConnection0);
                    udpConnection0.forceDisconnect("access-denied-server-busy-cs");
                    countOfDroppedConnections++;
                }

                LoggerManager.getLogger("user").write(udpConnection0.idStr + " \"" + string0 + "\" allowed to join");
                ServerWorldDatabase.LogonResult logonResult0 = ServerWorldDatabase.instance.new LogonResult();
                logonResult0.accessLevel = PlayerType.toString(udpConnection0.accessLevel);
                receiveClientConnect(udpConnection0, logonResult0);
            }
        } else {
            ServerWorldDatabase.LogonResult logonResult1 = ServerWorldDatabase.instance.authClient(string0, string1, udpConnection0.ip, udpConnection0.steamID);
            if (logonResult1.bAuthorized) {
                for (int int1 = 0; int1 < udpEngine.connections.size(); int1++) {
                    UdpConnection udpConnection2 = (UdpConnection)udpEngine.connections.get(int1);

                    for (int int2 = 0; int2 < 4; int2++) {
                        if (string0.equals(udpConnection2.usernames[int2])) {
                            LoggerManager.getLogger("user").write("access denied: user \"" + string0 + "\" already connected");
                            ByteBufferWriter byteBufferWriter5 = udpConnection0.startPacket();
                            PacketTypes.PacketType.AccessDenied.doPacket(byteBufferWriter5);
                            byteBufferWriter5.putUTF("AlreadyConnected");
                            PacketTypes.PacketType.AccessDenied.send(udpConnection0);
                            ConnectionManager.log("access-denied", "already-connected-username", udpConnection0);
                            udpConnection0.forceDisconnect("access-denied-already-connected-username");
                            return;
                        }
                    }
                }

                udpConnection0.username = string0;
                udpConnection0.usernames[0] = string0;
                transactionIDMap.put(string0, logonResult1.transactionID);
                if (CoopSlave.instance != null) {
                    udpConnection0.isCoopHost = udpEngine.connections.size() == 1;
                    DebugLog.log(udpConnection0.idStr + " isCoopHost=" + udpConnection0.isCoopHost);
                }

                udpConnection0.accessLevel = PlayerType.fromString(logonResult1.accessLevel);
                udpConnection0.preferredInQueue = logonResult1.priority;
                if (!ServerOptions.instance.DoLuaChecksum.getValue() || logonResult1.accessLevel.equals("admin")) {
                    udpConnection0.checksumState = UdpConnection.ChecksumState.Done;
                }

                if (!logonResult1.accessLevel.equals("") && getPlayerCount() >= ServerOptions.getInstance().getMaxPlayers()) {
                    ByteBufferWriter byteBufferWriter6 = udpConnection0.startPacket();
                    PacketTypes.PacketType.AccessDenied.doPacket(byteBufferWriter6);
                    byteBufferWriter6.putUTF("ServerFull");
                    PacketTypes.PacketType.AccessDenied.send(udpConnection0);
                    ConnectionManager.log("access-denied", "server-full-no-admin", udpConnection0);
                    udpConnection0.forceDisconnect("access-denied-server-full");
                    return;
                }

                if (!ServerWorldDatabase.instance.containsUser(string0) && ServerWorldDatabase.instance.containsCaseinsensitiveUser(string0)) {
                    ByteBufferWriter byteBufferWriter7 = udpConnection0.startPacket();
                    PacketTypes.PacketType.AccessDenied.doPacket(byteBufferWriter7);
                    byteBufferWriter7.putUTF("InvalidUsername");
                    PacketTypes.PacketType.AccessDenied.send(udpConnection0);
                    ConnectionManager.log("access-denied", "invalid-username", udpConnection0);
                    udpConnection0.forceDisconnect("access-denied-invalid-username");
                    return;
                }

                int int3 = udpConnection0.getAveragePing();
                DebugLog.Multiplayer.debugln("User %s ping %d ms", udpConnection0.username, int3);
                if (MPStatistics.doKickWhileLoading(udpConnection0, (long)int3)) {
                    ByteBufferWriter byteBufferWriter8 = udpConnection0.startPacket();
                    PacketTypes.PacketType.AccessDenied.doPacket(byteBufferWriter8);
                    LoggerManager.getLogger("user").write("access denied: user \"" + string0 + "\" ping is too high");
                    byteBufferWriter8.putUTF("Ping");
                    PacketTypes.PacketType.AccessDenied.send(udpConnection0);
                    ConnectionManager.log("access-denied", "ping-limit", udpConnection0);
                    udpConnection0.forceDisconnect("access-denied-ping-limit");
                    return;
                }

                if (logonResult1.newUser) {
                    try {
                        ServerWorldDatabase.instance.addUser(string0, string1);
                        LoggerManager.getLogger("user").write(udpConnection0.idStr + " \"" + string0 + "\" was added");
                    } catch (SQLException sQLException) {
                        DebugLog.Multiplayer.printException(sQLException, "ServerWorldDatabase.addUser error", LogSeverity.Error);
                    }
                }

                LoggerManager.getLogger("user").write(udpConnection0.idStr + " \"" + string0 + "\" allowed to join");

                try {
                    if (ServerOptions.instance.AutoCreateUserInWhiteList.getValue() && !ServerWorldDatabase.instance.containsUser(string0)) {
                        ServerWorldDatabase.instance.addUser(string0, string1);
                    } else {
                        ServerWorldDatabase.instance.setPassword(string0, string1);
                    }
                } catch (Exception exception) {
                    exception.printStackTrace();
                }

                ServerWorldDatabase.instance.updateLastConnectionDate(string0, string1);
                if (SteamUtils.isSteamModeEnabled()) {
                    String string3 = SteamUtils.convertSteamIDToString(udpConnection0.steamID);
                    ServerWorldDatabase.instance.setUserSteamID(string0, string3);
                }

                receiveClientConnect(udpConnection0, logonResult1);
            } else {
                ByteBufferWriter byteBufferWriter9 = udpConnection0.startPacket();
                PacketTypes.PacketType.AccessDenied.doPacket(byteBufferWriter9);
                if (logonResult1.banned) {
                    LoggerManager.getLogger("user").write("access denied: user \"" + string0 + "\" is banned");
                    if (logonResult1.bannedReason != null && !logonResult1.bannedReason.isEmpty()) {
                        byteBufferWriter9.putUTF("BannedReason##" + logonResult1.bannedReason);
                    } else {
                        byteBufferWriter9.putUTF("Banned");
                    }
                } else if (!logonResult1.bAuthorized) {
                    LoggerManager.getLogger("user").write("access denied: user \"" + string0 + "\" reason \"" + logonResult1.dcReason + "\"");
                    byteBufferWriter9.putUTF(logonResult1.dcReason != null ? logonResult1.dcReason : "AccessDenied");
                }

                PacketTypes.PacketType.AccessDenied.send(udpConnection0);
                ConnectionManager.log("access-denied", "unauthorized", udpConnection0);
                udpConnection0.forceDisconnect("access-denied-unauthorized");
            }
        }
    }

    static void receiveSendInventory(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        short _short = byteBuffer.getShort();
        Long _long = (Long)IDToAddressMap.get(_short);
        if (_long != null) {
            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection.getConnectedGUID() == _long) {
                    ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                    PacketTypes.PacketType.SendInventory.doPacket(byteBufferWriter);
                    byteBufferWriter.bb.put(byteBuffer);
                    PacketTypes.PacketType.SendInventory.send(udpConnection);
                    break;
                }
            }
        }
    }

    static void receivePlayerStartPMChat(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        ChatServer.getInstance().processPlayerStartWhisperChatPacket(byteBuffer);
    }

    static void receiveRequestInventory(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        short short0 = byteBuffer.getShort();
        short short1 = byteBuffer.getShort();
        Long _long = (Long)IDToAddressMap.get(short1);
        if (_long != null) {
            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection.getConnectedGUID() == _long) {
                    ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                    PacketTypes.PacketType.RequestInventory.doPacket(byteBufferWriter);
                    byteBufferWriter.putShort(short0);
                    PacketTypes.PacketType.RequestInventory.send(udpConnection);
                    break;
                }
            }
        }
    }

    static void receiveStatistic(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        try {
            udpConnection.statistic.parse(byteBuffer);
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    static void receiveStatisticRequest(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        if (udpConnection.accessLevel != 32 && !Core.bDebug) {
            DebugLog.General.error("User " + udpConnection.username + " has no rights to access statistics.");
        } else {
            try {
                udpConnection.statistic.enable = byteBuffer.get();
                sendStatistic(udpConnection);
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }
    }

    static void receiveZombieSimulation(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        NetworkZombiePacker.getInstance().receivePacket(byteBuffer, udpConnection);
    }

    public static void sendShortStatistic() {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            if (udpConnection.statistic.enable == 3) {
                sendShortStatistic(udpConnection);
            }
        }
    }

    public static void sendShortStatistic(UdpConnection c) {
        try {
            ByteBufferWriter byteBufferWriter = c.startPacket();
            PacketTypes.PacketType.StatisticRequest.doPacket(byteBufferWriter);
            MPStatistic.getInstance().write(byteBufferWriter);
            PacketTypes.PacketType.StatisticRequest.send(c);
        } catch (Exception exception) {
            exception.printStackTrace();
            c.cancelPacket();
        }
    }

    public static void sendStatistic() {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            if (udpConnection.statistic.enable == 1) {
                sendStatistic(udpConnection);
            }
        }
    }

    public static void sendStatistic(UdpConnection c) {
        ByteBufferWriter byteBufferWriter = c.startPacket();
        PacketTypes.PacketType.StatisticRequest.doPacket(byteBufferWriter);

        try {
            MPStatistic.getInstance().getStatisticTable(byteBufferWriter.bb);
            PacketTypes.PacketType.StatisticRequest.send(c);
        } catch (IOException iOException) {
            iOException.printStackTrace();
            c.cancelPacket();
        }
    }

    public static void getStatisticFromClients() {
        try {
            for (UdpConnection udpConnection : udpEngine.connections) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.Statistic.doPacket(byteBufferWriter);
                byteBufferWriter.putLong(System.currentTimeMillis());
                PacketTypes.PacketType.Statistic.send(udpConnection);
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    public static void updateZombieControl(IsoZombie zombie, short variableParam, int value) {
        try {
            if (zombie.authOwner == null) {
                return;
            }

            ByteBufferWriter byteBufferWriter = zombie.authOwner.startPacket();
            PacketTypes.PacketType.ZombieControl.doPacket(byteBufferWriter);
            byteBufferWriter.putShort(zombie.OnlineID);
            byteBufferWriter.putShort(variableParam);
            byteBufferWriter.putInt(value);
            PacketTypes.PacketType.ZombieControl.send(zombie.authOwner);
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    static void receivePlayerUpdate(ByteBuffer byteBuffer, UdpConnection udpConnection0, short _short) {
        if (udpConnection0.checksumState != UdpConnection.ChecksumState.Done) {
            kick(udpConnection0, "UI_Policy_Kick", null);
            udpConnection0.forceDisconnect("kick-checksum");
        } else {
            PlayerPacket playerPacket = PlayerPacket.l_receive.playerPacket;
            playerPacket.parse(byteBuffer, udpConnection0);
            IsoPlayer isoPlayer = getPlayerFromConnection(udpConnection0, playerPacket.id);

            try {
                if (isoPlayer == null) {
                    DebugLog.General
                        .error("receivePlayerUpdate: Server received position for unknown player (id:" + playerPacket.id + "). Server will ignore this data.");
                } else {
                    if (udpConnection0.accessLevel == 1
                        && isoPlayer.networkAI.doCheckAccessLevel()
                        && (
                                playerPacket.booleanVariables
                                    & (
                                        !zombie.SystemDisabler.getAllowDebugConnections() && !zombie.SystemDisabler.getOverrideServerConnectDebugCheck()
                                            ? '\uf000'
                                            : '\uc000'
                                    )
                            )
                            != 0
                        && ServerOptions.instance.AntiCheatProtectionType12.getValue()
                        && PacketValidator.checkUser(udpConnection0)) {
                        PacketValidator.doKickUser(udpConnection0, playerPacket.getClass().getSimpleName(), "Type12", null);
                    }

                    if (!isoPlayer.networkAI
                        .checkPosition(udpConnection0, isoPlayer, (float)PZMath.fastfloor(playerPacket.realx), (float)PZMath.fastfloor(playerPacket.realy))) {
                        return;
                    }

                    if (!isoPlayer.networkAI.isSetVehicleHit()) {
                        isoPlayer.networkAI.parse(playerPacket);
                    }

                    isoPlayer.bleedingLevel = playerPacket.bleedingLevel;
                    if (isoPlayer.networkAI.distance.getLength() > (float)IsoChunkMap.ChunkWidthInTiles) {
                        MPStatistic.getInstance().teleport();
                    }

                    udpConnection0.ReleventPos[isoPlayer.PlayerIndex].x = playerPacket.realx;
                    udpConnection0.ReleventPos[isoPlayer.PlayerIndex].y = playerPacket.realy;
                    udpConnection0.ReleventPos[isoPlayer.PlayerIndex].z = (float)playerPacket.realz;
                    playerPacket.id = isoPlayer.getOnlineID();
                }
            } catch (Exception exception) {
                exception.printStackTrace();
            }

            if (ServerOptions.instance.KickFastPlayers.getValue()) {
                Vector2 vector2 = (Vector2)playerToCoordsMap.get(Integer.valueOf(playerPacket.id));
                if (vector2 == null) {
                    vector2 = new Vector2();
                    vector2.x = playerPacket.x;
                    vector2.y = playerPacket.y;
                    playerToCoordsMap.put(playerPacket.id, vector2);
                } else {
                    if (!isoPlayer.accessLevel.equals("")
                        && !isoPlayer.isGhostMode()
                        && (Math.abs(playerPacket.x - vector2.x) > 4.0F || Math.abs(playerPacket.y - vector2.y) > 4.0F)) {
                        if (playerMovedToFastMap.get(playerPacket.id) == null) {
                            playerMovedToFastMap.put(playerPacket.id, 1);
                        } else {
                            playerMovedToFastMap.put(playerPacket.id, (Integer)playerMovedToFastMap.get(Integer.valueOf(playerPacket.id)) + 1);
                        }

                        LoggerManager.getLogger("admin")
                            .write(isoPlayer.getDisplayName() + " go too fast (" + playerMovedToFastMap.get(Integer.valueOf(playerPacket.id)) + " times)");
                        if ((Integer)playerMovedToFastMap.get(playerPacket.id) == 10) {
                            LoggerManager.getLogger("admin").write(isoPlayer.getDisplayName() + " kicked for going too fast");
                            kick(udpConnection0, "UI_Policy_Kick", null);
                            udpConnection0.forceDisconnect("kick-fast-player");
                            return;
                        }
                    }

                    vector2.x = playerPacket.x;
                    vector2.y = playerPacket.y;
                }
            }

            if (isoPlayer != null) {
                for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                    UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
                    if (udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID()
                        && udpConnection1.isFullyConnected()
                        && (
                            isoPlayer.checkCanSeeClient(udpConnection1) && udpConnection1.RelevantTo(playerPacket.x, playerPacket.y)
                                || _short == PacketTypes.PacketType.PlayerUpdateReliable.getId()
                                    && (udpConnection1.accessLevel > udpConnection0.accessLevel || udpConnection0.accessLevel == 32)
                        )) {
                        ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                        ((PacketTypes.PacketType)PacketTypes.packetTypes.get(_short)).doPacket(byteBufferWriter);
                        byteBuffer.position(0);
                        byteBuffer.position(2);
                        byteBufferWriter.bb.putShort(isoPlayer.getOnlineID());
                        byteBufferWriter.bb.put(byteBuffer);
                        ((PacketTypes.PacketType)PacketTypes.packetTypes.get(_short)).send(udpConnection1);
                    }
                }
            }
        }
    }

    static void receivePacketCounts(ByteBuffer var0, UdpConnection udpConnection, short var2) {
        ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
        PacketTypes.PacketType.PacketCounts.doPacket(byteBufferWriter);
        byteBufferWriter.putInt(PacketTypes.packetTypes.size());

        for (PacketTypes.PacketType packetType : PacketTypes.packetTypes.values()) {
            byteBufferWriter.putShort(packetType.getId());
            byteBufferWriter.putLong(packetType.serverPacketCount);
        }

        PacketTypes.PacketType.PacketCounts.send(udpConnection);
    }

    static void receiveSandboxOptions(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        try {
            zombie.SandboxOptions.instance.load(byteBuffer);
            zombie.SandboxOptions.instance.applySettings();
            zombie.SandboxOptions.instance.toLua();
            zombie.SandboxOptions.instance.saveServerLuaFile(ServerName);

            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.SandboxOptions.doPacket(byteBufferWriter);
                byteBuffer.rewind();
                byteBufferWriter.bb.put(byteBuffer);
                PacketTypes.PacketType.SandboxOptions.send(udpConnection);
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    static void receiveChunkObjectState(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        short short0 = byteBuffer.getShort();
        short short1 = byteBuffer.getShort();
        IsoChunk isoChunk = ServerMap.instance.getChunk(short0, short1);
        if (isoChunk == null) {
            udpConnection.chunkObjectState.add(short0);
            udpConnection.chunkObjectState.add(short1);
        } else {
            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
            PacketTypes.PacketType.ChunkObjectState.doPacket(byteBufferWriter);
            byteBufferWriter.putShort(short0);
            byteBufferWriter.putShort(short1);

            try {
                if (isoChunk.saveObjectState(byteBufferWriter.bb)) {
                    PacketTypes.PacketType.ChunkObjectState.send(udpConnection);
                } else {
                    udpConnection.cancelPacket();
                }
            } catch (Throwable throwable) {
                throwable.printStackTrace();
                udpConnection.cancelPacket();
                return;
            }
        }
    }

    static void receiveReadAnnotedMap(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        String string = zombie.GameWindow.ReadString(byteBuffer);
        StashSystem.prepareBuildingStash(string);
    }

    static void receiveTradingUIRemoveItem(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        short short0 = byteBuffer.getShort();
        short short1 = byteBuffer.getShort();
        int int0 = byteBuffer.getInt();
        Long _long = (Long)IDToAddressMap.get(short1);
        if (_long != null) {
            for (int int1 = 0; int1 < udpEngine.connections.size(); int1++) {
                UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(int1);
                if (udpConnection.getConnectedGUID() == _long) {
                    ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                    PacketTypes.PacketType.TradingUIRemoveItem.doPacket(byteBufferWriter);
                    byteBufferWriter.putShort(short0);
                    byteBufferWriter.putInt(int0);
                    PacketTypes.PacketType.TradingUIRemoveItem.send(udpConnection);
                    break;
                }
            }
        }
    }

    static void receiveTradingUIUpdateState(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        short short0 = byteBuffer.getShort();
        short short1 = byteBuffer.getShort();
        int int0 = byteBuffer.getInt();
        Long _long = (Long)IDToAddressMap.get(short1);
        if (_long != null) {
            for (int int1 = 0; int1 < udpEngine.connections.size(); int1++) {
                UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(int1);
                if (udpConnection.getConnectedGUID() == _long) {
                    ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                    PacketTypes.PacketType.TradingUIUpdateState.doPacket(byteBufferWriter);
                    byteBufferWriter.putShort(short0);
                    byteBufferWriter.putInt(int0);
                    PacketTypes.PacketType.TradingUIUpdateState.send(udpConnection);
                    break;
                }
            }
        }
    }

    static void receiveTradingUIAddItem(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        short short0 = byteBuffer.getShort();
        short short1 = byteBuffer.getShort();
        InventoryItem inventoryItem = null;

        try {
            inventoryItem = InventoryItem.loadItem(byteBuffer, 195);
        } catch (Exception exception) {
            exception.printStackTrace();
        }

        if (inventoryItem != null) {
            Long _long = (Long)IDToAddressMap.get(short1);
            if (_long != null) {
                for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                    UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
                    if (udpConnection.getConnectedGUID() == _long) {
                        ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                        PacketTypes.PacketType.TradingUIAddItem.doPacket(byteBufferWriter);
                        byteBufferWriter.putShort(short0);

                        try {
                            inventoryItem.saveWithSize(byteBufferWriter.bb, false);
                        } catch (IOException iOException) {
                            iOException.printStackTrace();
                        }

                        PacketTypes.PacketType.TradingUIAddItem.send(udpConnection);
                        break;
                    }
                }
            }
        }
    }

    static void receiveRequestTrading(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        short short0 = byteBuffer.getShort();
        short short1 = byteBuffer.getShort();
        byte _byte = byteBuffer.get();
        Long _long = (Long)IDToAddressMap.get(short0);
        if (_byte == 0) {
            _long = (Long)IDToAddressMap.get(short1);
        }

        if (_long != null) {
            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection.getConnectedGUID() == _long) {
                    ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                    PacketTypes.PacketType.RequestTrading.doPacket(byteBufferWriter);
                    if (_byte == 0) {
                        byteBufferWriter.putShort(short0);
                    } else {
                        byteBufferWriter.putShort(short1);
                    }

                    byteBufferWriter.putByte(_byte);
                    PacketTypes.PacketType.RequestTrading.send(udpConnection);
                    break;
                }
            }
        }
    }

    static void receiveSyncFaction(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        String string0 = zombie.GameWindow.ReadString(byteBuffer);
        String string1 = zombie.GameWindow.ReadString(byteBuffer);
        int int0 = byteBuffer.getInt();
        Faction faction = Faction.getFaction(string0);
        boolean boolean0 = false;
        if (faction == null) {
            faction = new Faction(string0, string1);
            boolean0 = true;
            Faction.getFactions().add(faction);
        }

        faction.getPlayers().clear();
        if (byteBuffer.get() == 1) {
            faction.setTag(zombie.GameWindow.ReadString(byteBuffer));
            faction.setTagColor(new ColorInfo(byteBuffer.getFloat(), byteBuffer.getFloat(), byteBuffer.getFloat(), 1.0F));
        }

        for (int int1 = 0; int1 < int0; int1++) {
            String string2 = zombie.GameWindow.ReadString(byteBuffer);
            faction.getPlayers().add(string2);
        }

        if (!faction.getOwner().equals(string1)) {
            faction.setOwner(string1);
        }

        boolean boolean1 = byteBuffer.get() == 1;
        if (ChatServer.isInited()) {
            if (boolean0) {
                ChatServer.getInstance().createFactionChat(string0);
            }

            if (boolean1) {
                ChatServer.getInstance().removeFactionChat(string0);
            } else {
                ChatServer.getInstance().syncFactionChatMembers(string0, string1, faction.getPlayers());
            }
        }

        if (boolean1) {
            Faction.getFactions().remove(faction);
            DebugLog.log("faction: removed " + string0 + " owner=" + faction.getOwner());
        }

        for (int int2 = 0; int2 < udpEngine.connections.size(); int2++) {
            UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int2);
            if (udpConnection1 == null || udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID()) {
                ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                PacketTypes.PacketType.SyncFaction.doPacket(byteBufferWriter);
                faction.writeToBuffer(byteBufferWriter, boolean1);
                PacketTypes.PacketType.SyncFaction.send(udpConnection0);
            }
        }
    }

    static void receiveSyncNonPvpZone(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        try {
            SyncNonPvpZonePacket syncNonPvpZonePacket = new SyncNonPvpZonePacket();
            syncNonPvpZonePacket.parse(byteBuffer, udpConnection);
            if (syncNonPvpZonePacket.isConsistent()) {
                sendNonPvpZone(syncNonPvpZonePacket.zone, syncNonPvpZonePacket.doRemove, udpConnection);
                syncNonPvpZonePacket.process();
                DebugLog.Multiplayer.debugln("ReceiveSyncNonPvpZone: %s", syncNonPvpZonePacket.getDescription());
            }
        } catch (Exception exception) {
            DebugLog.Multiplayer.printException(exception, "ReceiveSyncNonPvpZone: failed", LogSeverity.Error);
        }
    }

    public static void sendNonPvpZone(NonPvpZone zone, boolean remove, UdpConnection connection) {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            if (connection == null || udpConnection.getConnectedGUID() != connection.getConnectedGUID()) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.SyncNonPvpZone.doPacket(byteBufferWriter);
                zone.save(byteBufferWriter.bb);
                byteBufferWriter.putBoolean(remove);
                PacketTypes.PacketType.SyncNonPvpZone.send(udpConnection);
            }
        }
    }

    static void receiveChangeTextColor(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        short _short = byteBuffer.getShort();
        IsoPlayer isoPlayer = getPlayerFromConnection(udpConnection0, _short);
        if (isoPlayer != null) {
            float float0 = byteBuffer.getFloat();
            float float1 = byteBuffer.getFloat();
            float float2 = byteBuffer.getFloat();
            isoPlayer.setSpeakColourInfo(new ColorInfo(float0, float1, float2, 1.0F));

            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()) {
                    ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                    PacketTypes.PacketType.ChangeTextColor.doPacket(byteBufferWriter);
                    byteBufferWriter.putShort(isoPlayer.getOnlineID());
                    byteBufferWriter.putFloat(float0);
                    byteBufferWriter.putFloat(float1);
                    byteBufferWriter.putFloat(float2);
                    PacketTypes.PacketType.ChangeTextColor.send(udpConnection1);
                }
            }
        }
    }

    @Deprecated
    static void receiveTransactionID(ByteBuffer byteBuffer, UdpConnection var1) {
        short _short = byteBuffer.getShort();
        int _int = byteBuffer.getInt();
        IsoPlayer isoPlayer = (IsoPlayer)IDToPlayerMap.get(_short);
        if (isoPlayer != null) {
            transactionIDMap.put(isoPlayer.username, _int);
            isoPlayer.setTransactionID(_int);
            ServerWorldDatabase.instance.saveTransactionID(isoPlayer.username, _int);
        }
    }

    static void receiveSyncCompost(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare(int0, int1, int2);
        if (isoGridSquare != null) {
            IsoCompost isoCompost = isoGridSquare.getCompost();
            if (isoCompost == null) {
                isoCompost = new IsoCompost(isoGridSquare.getCell(), isoGridSquare);
                isoGridSquare.AddSpecialObject(isoCompost);
            }

            float _float = byteBuffer.getFloat();
            isoCompost.setCompost(_float);
            sendCompost(isoCompost, udpConnection);
        }
    }

    public static void sendCompost(IsoCompost compost, UdpConnection connection) {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            if (udpConnection.RelevantTo((float)compost.square.x, (float)compost.square.y)
                && (connection != null && udpConnection.getConnectedGUID() != connection.getConnectedGUID() || connection == null)) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.SyncCompost.doPacket(byteBufferWriter);
                byteBufferWriter.putInt(compost.square.x);
                byteBufferWriter.putInt(compost.square.y);
                byteBufferWriter.putInt(compost.square.z);
                byteBufferWriter.putFloat(compost.getCompost());
                PacketTypes.PacketType.SyncCompost.send(udpConnection);
            }
        }
    }

    static void receiveCataplasm(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        short _short = byteBuffer.getShort();
        IsoPlayer isoPlayer = (IsoPlayer)IDToPlayerMap.get(_short);
        if (isoPlayer != null) {
            int int0 = byteBuffer.getInt();
            float float0 = byteBuffer.getFloat();
            float float1 = byteBuffer.getFloat();
            float float2 = byteBuffer.getFloat();
            if (float0 > 0.0F) {
                isoPlayer.getBodyDamage().getBodyPart(BodyPartType.FromIndex(int0)).setPlantainFactor(float0);
            }

            if (float1 > 0.0F) {
                isoPlayer.getBodyDamage().getBodyPart(BodyPartType.FromIndex(int0)).setComfreyFactor(float1);
            }

            if (float2 > 0.0F) {
                isoPlayer.getBodyDamage().getBodyPart(BodyPartType.FromIndex(int0)).setGarlicFactor(float2);
            }

            for (int int1 = 0; int1 < udpEngine.connections.size(); int1++) {
                UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int1);
                if (udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID()) {
                    ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                    PacketTypes.PacketType.Cataplasm.doPacket(byteBufferWriter);
                    byteBufferWriter.putShort(_short);
                    byteBufferWriter.putInt(int0);
                    byteBufferWriter.putFloat(float0);
                    byteBufferWriter.putFloat(float1);
                    byteBufferWriter.putFloat(float2);
                    PacketTypes.PacketType.Cataplasm.send(udpConnection0);
                }
            }
        }
    }

    static void receiveSledgehammerDestroy(ByteBuffer byteBuffer, UdpConnection udpConnection, short _short) {
        if (ServerOptions.instance.AllowDestructionBySledgehammer.getValue()) {
            receiveRemoveItemFromSquare(byteBuffer, udpConnection, _short);
        }
    }

    public static void AddExplosiveTrap(HandWeapon weapon, IsoGridSquare sq, boolean sensor) {
        IsoTrap isoTrap = new IsoTrap(weapon, sq.getCell(), sq);
        int int0 = 0;
        if (weapon.getExplosionRange() > 0) {
            int0 = weapon.getExplosionRange();
        }

        if (weapon.getFireRange() > 0) {
            int0 = weapon.getFireRange();
        }

        if (weapon.getSmokeRange() > 0) {
            int0 = weapon.getSmokeRange();
        }

        sq.AddTileObject(isoTrap);

        for (int int1 = 0; int1 < udpEngine.connections.size(); int1++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(int1);
            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
            PacketTypes.PacketType.AddExplosiveTrap.doPacket(byteBufferWriter);
            byteBufferWriter.putInt(sq.x);
            byteBufferWriter.putInt(sq.y);
            byteBufferWriter.putInt(sq.z);

            try {
                weapon.saveWithSize(byteBufferWriter.bb, false);
            } catch (IOException iOException) {
                iOException.printStackTrace();
            }

            byteBufferWriter.putInt(int0);
            byteBufferWriter.putBoolean(sensor);
            byteBufferWriter.putBoolean(false);
            PacketTypes.PacketType.AddExplosiveTrap.send(udpConnection);
        }
    }

    static void receiveAddExplosiveTrap(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare(int0, int1, int2);
        if (isoGridSquare != null) {
            InventoryItem inventoryItem = null;

            try {
                inventoryItem = InventoryItem.loadItem(byteBuffer, 195);
            } catch (Exception exception) {
                exception.printStackTrace();
            }

            if (inventoryItem == null) {
                return;
            }

            HandWeapon handWeapon = (HandWeapon)inventoryItem;
            DebugLog.log("trap: user \"" + udpConnection0.username + "\" added " + inventoryItem.getFullType() + " at " + int0 + "," + int1 + "," + int2);
            LoggerManager.getLogger("map")
                .write(
                    udpConnection0.idStr
                        + " \""
                        + udpConnection0.username
                        + "\" added "
                        + inventoryItem.getFullType()
                        + " at "
                        + int0
                        + ","
                        + int1
                        + ","
                        + int2
                );
            if (handWeapon.isInstantExplosion()) {
                IsoTrap isoTrap = new IsoTrap(handWeapon, isoGridSquare.getCell(), isoGridSquare);
                isoGridSquare.AddTileObject(isoTrap);
                isoTrap.triggerExplosion(false);
            }

            for (int int3 = 0; int3 < udpEngine.connections.size(); int3++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(int3);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()) {
                    ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                    PacketTypes.PacketType.AddExplosiveTrap.doPacket(byteBufferWriter);
                    byteBufferWriter.putInt(int0);
                    byteBufferWriter.putInt(int1);
                    byteBufferWriter.putInt(int2);

                    try {
                        handWeapon.saveWithSize(byteBufferWriter.bb, false);
                    } catch (IOException iOException) {
                        iOException.printStackTrace();
                    }

                    PacketTypes.PacketType.AddExplosiveTrap.send(udpConnection1);
                }
            }
        }
    }

    public static void sendHelicopter(float x, float y, boolean active) {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
            PacketTypes.PacketType.Helicopter.doPacket(byteBufferWriter);
            byteBufferWriter.putFloat(x);
            byteBufferWriter.putFloat(y);
            byteBufferWriter.putBoolean(active);
            PacketTypes.PacketType.Helicopter.send(udpConnection);
        }
    }

    static void receiveRegisterZone(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        String string0 = zombie.GameWindow.ReadString(byteBuffer);
        String string1 = zombie.GameWindow.ReadString(byteBuffer);
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        int int3 = byteBuffer.getInt();
        int int4 = byteBuffer.getInt();
        int int5 = byteBuffer.getInt();
        boolean boolean0 = byteBuffer.get() == 1;
        ArrayList arrayList = IsoWorld.instance.getMetaGrid().getZonesAt(int0, int1, int2);
        boolean boolean1 = false;

        for (IsoMetaGrid.Zone zone : arrayList) {
            if (string1.equals(zone.getType())) {
                boolean1 = true;
                zone.setName(string0);
                zone.setLastActionTimestamp(int5);
            }
        }

        if (!boolean1) {
            IsoWorld.instance.getMetaGrid().registerZone(string0, string1, int0, int1, int2, int3, int4);
        }

        if (boolean0) {
            for (int int6 = 0; int6 < udpEngine.connections.size(); int6++) {
                UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int6);
                if (udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID()) {
                    ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                    PacketTypes.PacketType.RegisterZone.doPacket(byteBufferWriter);
                    byteBufferWriter.putUTF(string0);
                    byteBufferWriter.putUTF(string1);
                    byteBufferWriter.putInt(int0);
                    byteBufferWriter.putInt(int1);
                    byteBufferWriter.putInt(int2);
                    byteBufferWriter.putInt(int3);
                    byteBufferWriter.putInt(int4);
                    byteBufferWriter.putInt(int5);
                    PacketTypes.PacketType.RegisterZone.send(udpConnection0);
                }
            }
        }
    }

    public static void sendZone(IsoMetaGrid.Zone zone, UdpConnection connection) {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            if (connection == null || udpConnection.getConnectedGUID() != connection.getConnectedGUID()) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.RegisterZone.doPacket(byteBufferWriter);
                byteBufferWriter.putUTF(zone.name);
                byteBufferWriter.putUTF(zone.type);
                byteBufferWriter.putInt(zone.x);
                byteBufferWriter.putInt(zone.y);
                byteBufferWriter.putInt(zone.z);
                byteBufferWriter.putInt(zone.w);
                byteBufferWriter.putInt(zone.h);
                byteBufferWriter.putInt(zone.lastActionTimestamp);
                PacketTypes.PacketType.RegisterZone.send(udpConnection);
            }
        }
    }

    static void receiveConstructedZone(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        IsoMetaGrid.Zone zone = IsoWorld.instance.MetaGrid.getZoneAt(int0, int1, int2);
        if (zone != null) {
            zone.setHaveConstruction(true);
        }
    }

    public static void addXp(IsoPlayer p, PerkFactory.Perk perk, int xp) {
        if (PlayerToAddressMap.containsKey(p)) {
            long _long = (Long)PlayerToAddressMap.get(p);
            UdpConnection udpConnection = udpEngine.getActiveConnection(_long);
            if (udpConnection == null) {
                return;
            }

            AddXp addXp = new AddXp();
            addXp.set(p, perk, xp);
            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
            PacketTypes.PacketType.AddXP.doPacket(byteBufferWriter);
            addXp.write(byteBufferWriter);
            PacketTypes.PacketType.AddXP.send(udpConnection);
        }
    }

    static void receiveWriteLog(ByteBuffer var0, UdpConnection var1, short var2) {
    }

    static void receiveChecksum(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        NetChecksum.comparer.serverPacket(byteBuffer, udpConnection);
    }

    private static void answerPing(ByteBuffer byteBuffer, UdpConnection udpConnection1) {
        String string = zombie.GameWindow.ReadString(byteBuffer);

        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(_int);
            if (udpConnection0.getConnectedGUID() == udpConnection1.getConnectedGUID()) {
                ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                PacketTypes.PacketType.Ping.doPacket(byteBufferWriter);
                byteBufferWriter.putUTF(string);
                byteBufferWriter.putInt(udpEngine.connections.size());
                byteBufferWriter.putInt(512);
                PacketTypes.PacketType.Ping.send(udpConnection0);
            }
        }
    }

    static void receiveUpdateItemSprite(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        int int0 = byteBuffer.getInt();
        String string = zombie.GameWindow.ReadStringUTF(byteBuffer);
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        int int3 = byteBuffer.getInt();
        int int4 = byteBuffer.getInt();
        IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare(int1, int2, int3);
        if (isoGridSquare != null && int4 < isoGridSquare.getObjects().size()) {
            try {
                IsoObject isoObject = isoGridSquare.getObjects().get(int4);
                if (isoObject != null) {
                    isoObject.sprite = IsoSpriteManager.instance.getSprite(int0);
                    if (isoObject.sprite == null && !string.isEmpty()) {
                        isoObject.setSprite(string);
                    }

                    isoObject.RemoveAttachedAnims();
                    int int5 = byteBuffer.get() & 255;

                    for (int int6 = 0; int6 < int5; int6++) {
                        int int7 = byteBuffer.getInt();
                        IsoSprite isoSprite = IsoSpriteManager.instance.getSprite(int7);
                        if (isoSprite != null) {
                            isoObject.AttachExistingAnim(isoSprite, 0, 0, false, 0, false, 0.0F);
                        }
                    }

                    isoObject.transmitUpdatedSpriteToClients(udpConnection);
                }
            } catch (Exception exception) {
            }
        }
    }

    static void receiveWorldMessage(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        if (!udpConnection0.allChatMuted) {
            String string0 = zombie.GameWindow.ReadString(byteBuffer);
            String string1 = zombie.GameWindow.ReadString(byteBuffer);
            if (string1.length() > 256) {
                string1 = string1.substring(0, 256);
            }

            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
                ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                PacketTypes.PacketType.WorldMessage.doPacket(byteBufferWriter);
                byteBufferWriter.putUTF(string0);
                byteBufferWriter.putUTF(string1);
                PacketTypes.PacketType.WorldMessage.send(udpConnection1);
            }

            discordBot.sendMessage(string0, string1);
            LoggerManager.getLogger("chat").write(udpConnection0.index + " \"" + udpConnection0.username + "\" A \"" + string1 + "\"");
        }
    }

    static void receiveGetModData(ByteBuffer var0, UdpConnection var1, short var2) {
        LuaEventManager.triggerEvent("SendCustomModData");
    }

    static void receiveStopFire(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        byte _byte = byteBuffer.get();
        if (_byte == 1) {
            short short0 = byteBuffer.getShort();
            IsoPlayer isoPlayer = (IsoPlayer)IDToPlayerMap.get(short0);
            if (isoPlayer != null) {
                isoPlayer.sendObjectChange("StopBurning");
            }
        } else if (_byte == 2) {
            short short1 = byteBuffer.getShort();
            IsoZombie isoZombie = ServerMap.instance.ZombieMap.get(short1);
            if (isoZombie != null) {
                isoZombie.StopBurning();
            }
        } else {
            int int0 = byteBuffer.getInt();
            int int1 = byteBuffer.getInt();
            int int2 = byteBuffer.getInt();
            IsoGridSquare isoGridSquare = ServerMap.instance.getGridSquare(int0, int1, int2);
            if (isoGridSquare != null) {
                isoGridSquare.stopFire();

                for (int int3 = 0; int3 < udpEngine.connections.size(); int3++) {
                    UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int3);
                    if (udpConnection0.RelevantTo((float)int0, (float)int1) && udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID()) {
                        ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                        PacketTypes.PacketType.StopFire.doPacket(byteBufferWriter);
                        byteBufferWriter.putInt(int0);
                        byteBufferWriter.putInt(int1);
                        byteBufferWriter.putInt(int2);
                        PacketTypes.PacketType.StopFire.send(udpConnection0);
                    }
                }
            }
        }
    }

    @Deprecated
    static void receiveStartFire(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        StartFire startFire = new StartFire();
        startFire.parse(byteBuffer, udpConnection0);
        if (startFire.isConsistent() && startFire.validate(udpConnection0)) {
            startFire.process();

            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()) {
                    ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                    PacketTypes.PacketType.StartFire.doPacket(byteBufferWriter);
                    startFire.write(byteBufferWriter);
                    PacketTypes.PacketType.StartFire.send(udpConnection1);
                }
            }
        }
    }

    public static void startFireOnClient(IsoGridSquare gridSquare, int fireStartingEnergy, boolean igniteOnAny, int Life, boolean smoke) {
        StartFire startFire = new StartFire();
        startFire.set(gridSquare, igniteOnAny, fireStartingEnergy, Life, smoke);
        startFire.process();

        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            if (udpConnection.RelevantTo((float)gridSquare.getX(), (float)gridSquare.getY())) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.StartFire.doPacket(byteBufferWriter);
                startFire.write(byteBufferWriter);
                PacketTypes.PacketType.StartFire.send(udpConnection);
            }
        }
    }

    public static void sendOptionsToClients() {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
            PacketTypes.PacketType.ReloadOptions.doPacket(byteBufferWriter);
            byteBufferWriter.putInt(ServerOptions.instance.getPublicOptions().size());
            Object object = null;

            for (String string : ServerOptions.instance.getPublicOptions()) {
                byteBufferWriter.putUTF(string);
                byteBufferWriter.putUTF(ServerOptions.instance.getOption(string));
            }

            PacketTypes.PacketType.ReloadOptions.send(udpConnection);
        }
    }

    public static void sendBecomeCorpse(IsoDeadBody body) {
        IsoGridSquare isoGridSquare = body.getSquare();
        if (isoGridSquare != null) {
            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection.RelevantTo((float)isoGridSquare.x, (float)isoGridSquare.y)) {
                    ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                    PacketTypes.PacketType.BecomeCorpse.doPacket(byteBufferWriter);

                    try {
                        byteBufferWriter.putShort(body.getObjectID());
                        byteBufferWriter.putShort(body.getOnlineID());
                        byteBufferWriter.putFloat(body.getReanimateTime());
                        if (body.isPlayer()) {
                            byteBufferWriter.putByte((byte)2);
                        } else if (body.isZombie()) {
                            byteBufferWriter.putByte((byte)1);
                        } else {
                            byteBufferWriter.putByte((byte)0);
                        }

                        byteBufferWriter.putInt(isoGridSquare.x);
                        byteBufferWriter.putInt(isoGridSquare.y);
                        byteBufferWriter.putInt(isoGridSquare.z);
                        PacketTypes.PacketType.BecomeCorpse.send(udpConnection);
                    } catch (Exception exception) {
                        udpConnection.cancelPacket();
                        DebugLog.Multiplayer.printException(exception, "SendBecomeCorpse failed", LogSeverity.Error);
                    }
                }
            }
        }
    }

    public static void sendCorpse(IsoDeadBody body) {
        IsoGridSquare isoGridSquare = body.getSquare();
        if (isoGridSquare != null) {
            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection.RelevantTo((float)isoGridSquare.x, (float)isoGridSquare.y)) {
                    ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                    PacketTypes.PacketType.AddCorpseToMap.doPacket(byteBufferWriter);
                    byteBufferWriter.putShort(body.getObjectID());
                    byteBufferWriter.putShort(body.getOnlineID());
                    byteBufferWriter.putInt(isoGridSquare.x);
                    byteBufferWriter.putInt(isoGridSquare.y);
                    byteBufferWriter.putInt(isoGridSquare.z);
                    body.writeToRemoteBuffer(byteBufferWriter);
                    PacketTypes.PacketType.AddCorpseToMap.send(udpConnection);
                }
            }
        }
    }

    static void receiveAddCorpseToMap(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        short short0 = byteBuffer.getShort();
        short short1 = byteBuffer.getShort();
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        IsoObject isoObject = WorldItemTypes.createFromBuffer(byteBuffer);
        if (isoObject != null && isoObject instanceof IsoDeadBody) {
            isoObject.loadFromRemoteBuffer(byteBuffer, false);
            ((IsoDeadBody)isoObject).setObjectID(short0);
            IsoGridSquare isoGridSquare = ServerMap.instance.getGridSquare(int0, int1, int2);
            if (isoGridSquare != null) {
                isoGridSquare.addCorpse((IsoDeadBody)isoObject, true);

                for (int int3 = 0; int3 < udpEngine.connections.size(); int3++) {
                    UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int3);
                    if (udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID() && udpConnection0.RelevantTo((float)int0, (float)int1)) {
                        ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                        PacketTypes.PacketType.AddCorpseToMap.doPacket(byteBufferWriter);
                        byteBuffer.rewind();
                        byteBufferWriter.bb.put(byteBuffer);
                        PacketTypes.PacketType.AddCorpseToMap.send(udpConnection0);
                    }
                }
            }

            LoggerManager.getLogger("item").write(udpConnection1.idStr + " \"" + udpConnection1.username + "\" corpse +1 " + int0 + "," + int1 + "," + int2);
        }
    }

    static void receiveSmashWindow(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        IsoObject isoObject = IsoWorld.instance.getItemFromXYZIndexBuffer(byteBuffer);
        if (isoObject != null && isoObject instanceof IsoWindow) {
            byte _byte = byteBuffer.get();
            if (_byte == 1) {
                ((IsoWindow)isoObject).smashWindow(true);
                smashWindow((IsoWindow)isoObject, 1);
            } else if (_byte == 2) {
                ((IsoWindow)isoObject).setGlassRemoved(true);
                smashWindow((IsoWindow)isoObject, 2);
            }
        }
    }

    public static void sendPlayerConnect(IsoPlayer p, UdpConnection c) {
        ByteBufferWriter byteBufferWriter = c.startPacket();
        PacketTypes.PacketType.PlayerConnect.doPacket(byteBufferWriter);
        if (c.getConnectedGUID() != (Long)PlayerToAddressMap.get(p)) {
            byteBufferWriter.putShort(p.OnlineID);
        } else {
            byteBufferWriter.putShort((short)-1);
            byteBufferWriter.putByte((byte)p.PlayerIndex);
            byteBufferWriter.putShort(p.OnlineID);

            try {
                zombie.GameTime.getInstance().saveToPacket(byteBufferWriter.bb);
            } catch (IOException iOException0) {
                iOException0.printStackTrace();
            }
        }

        byteBufferWriter.putFloat(p.x);
        byteBufferWriter.putFloat(p.y);
        byteBufferWriter.putFloat(p.z);
        byteBufferWriter.putUTF(p.username);
        if (c.getConnectedGUID() != (Long)PlayerToAddressMap.get(p)) {
            try {
                p.getDescriptor().save(byteBufferWriter.bb);
                p.getHumanVisual().save(byteBufferWriter.bb);
                ItemVisuals itemVisuals = new ItemVisuals();
                p.getItemVisuals(itemVisuals);
                itemVisuals.save(byteBufferWriter.bb);
            } catch (IOException iOException1) {
                iOException1.printStackTrace();
            }
        }

        if (SteamUtils.isSteamModeEnabled()) {
            byteBufferWriter.putLong(p.getSteamID());
        }

        byteBufferWriter.putByte((byte)(p.isGodMod() ? 1 : 0));
        byteBufferWriter.putByte((byte)(p.isGhostMode() ? 1 : 0));
        p.getSafety().save(byteBufferWriter.bb);
        byteBufferWriter.putByte(PlayerType.fromString(p.accessLevel));
        byteBufferWriter.putByte((byte)(p.isInvisible() ? 1 : 0));
        if (c.getConnectedGUID() != (Long)PlayerToAddressMap.get(p)) {
            try {
                p.getXp().save(byteBufferWriter.bb);
            } catch (IOException iOException2) {
                iOException2.printStackTrace();
            }
        }

        byteBufferWriter.putUTF(p.getTagPrefix());
        byteBufferWriter.putFloat(p.getTagColor().r);
        byteBufferWriter.putFloat(p.getTagColor().g);
        byteBufferWriter.putFloat(p.getTagColor().b);
        byteBufferWriter.putDouble(p.getHoursSurvived());
        byteBufferWriter.putInt(p.getZombieKills());
        byteBufferWriter.putUTF(p.getDisplayName());
        byteBufferWriter.putFloat(p.getSpeakColour().r);
        byteBufferWriter.putFloat(p.getSpeakColour().g);
        byteBufferWriter.putFloat(p.getSpeakColour().b);
        byteBufferWriter.putBoolean(p.showTag);
        byteBufferWriter.putBoolean(p.factionPvp);
        byteBufferWriter.putInt(p.getAttachedItems().size());

        for (int _int = 0; _int < p.getAttachedItems().size(); _int++) {
            byteBufferWriter.putUTF(p.getAttachedItems().get(_int).getLocation());
            byteBufferWriter.putUTF(p.getAttachedItems().get(_int).getItem().getFullType());
        }

        byteBufferWriter.putInt(p.remoteSneakLvl);
        byteBufferWriter.putInt(p.remoteStrLvl);
        byteBufferWriter.putInt(p.remoteFitLvl);
        PacketTypes.PacketType.PlayerConnect.send(c);
        if (c.getConnectedGUID() != (Long)PlayerToAddressMap.get(p)) {
            updateHandEquips(c, p);
        }
    }

    @Deprecated
    static void receiveRequestPlayerData(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        IsoPlayer isoPlayer = (IsoPlayer)IDToPlayerMap.get(byteBuffer.getShort());
        if (isoPlayer != null) {
            sendPlayerConnect(isoPlayer, udpConnection);
        }
    }

    static void receiveChatMessageFromPlayer(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        ChatServer.getInstance().processMessageFromPlayerPacket(byteBuffer);
    }

    public static void loadModData(IsoGridSquare sq) {
        if (sq.getModData().rawget("id") != null
            && sq.getModData().rawget("id") != null
            && (sq.getModData().rawget("remove") == null || ((String)sq.getModData().rawget("remove")).equals("false"))) {
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":x", new Double((double)sq.getX()));
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":y", new Double((double)sq.getY()));
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":z", new Double((double)sq.getZ()));
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":typeOfSeed", sq.getModData().rawget("typeOfSeed"));
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":nbOfGrow", (Double)sq.getModData().rawget("nbOfGrow"));
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":id", sq.getModData().rawget("id"));
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":waterLvl", sq.getModData().rawget("waterLvl"));
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":lastWaterHour", sq.getModData().rawget("lastWaterHour"));
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":waterNeeded", sq.getModData().rawget("waterNeeded"));
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":waterNeededMax", sq.getModData().rawget("waterNeededMax"));
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":mildewLvl", sq.getModData().rawget("mildewLvl"));
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":aphidLvl", sq.getModData().rawget("aphidLvl"));
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":fliesLvl", sq.getModData().rawget("fliesLvl"));
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":fertilizer", sq.getModData().rawget("fertilizer"));
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":nextGrowing", sq.getModData().rawget("nextGrowing"));
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":hasVegetable", sq.getModData().rawget("hasVegetable"));
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":hasSeed", sq.getModData().rawget("hasSeed"));
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":health", sq.getModData().rawget("health"));
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":badCare", sq.getModData().rawget("badCare"));
            zombie.GameTime.getInstance()
                .getModData()
                .rawset("planting:" + ((Double)sq.getModData().rawget("id")).intValue() + ":state", sq.getModData().rawget("state"));
            if (sq.getModData().rawget("hoursElapsed") != null) {
                zombie.GameTime.getInstance().getModData().rawset("hoursElapsed", sq.getModData().rawget("hoursElapsed"));
            }
        }

        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            if (udpConnection.RelevantTo((float)sq.getX(), (float)sq.getY())) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.ReceiveModData.doPacket(byteBufferWriter);
                byteBufferWriter.putInt(sq.getX());
                byteBufferWriter.putInt(sq.getY());
                byteBufferWriter.putInt(sq.getZ());

                try {
                    sq.getModData().save(byteBufferWriter.bb);
                } catch (IOException iOException) {
                    iOException.printStackTrace();
                }

                PacketTypes.PacketType.ReceiveModData.send(udpConnection);
            }
        }
    }

    static void receiveSendModData(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        IsoGridSquare isoGridSquare = ServerMap.instance.getGridSquare(int0, int1, int2);
        if (isoGridSquare != null) {
            try {
                isoGridSquare.getModData().load(byteBuffer, 195);
                if (isoGridSquare.getModData().rawget("id") != null
                    && (isoGridSquare.getModData().rawget("remove") == null || ((String)isoGridSquare.getModData().rawget("remove")).equals("false"))) {
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset("planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":x", new Double((double)isoGridSquare.getX()));
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset("planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":y", new Double((double)isoGridSquare.getY()));
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset("planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":z", new Double((double)isoGridSquare.getZ()));
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset(
                            "planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":typeOfSeed",
                            isoGridSquare.getModData().rawget("typeOfSeed")
                        );
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset(
                            "planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":nbOfGrow",
                            (Double)isoGridSquare.getModData().rawget("nbOfGrow")
                        );
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset("planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":id", isoGridSquare.getModData().rawget("id"));
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset(
                            "planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":waterLvl",
                            isoGridSquare.getModData().rawget("waterLvl")
                        );
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset(
                            "planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":lastWaterHour",
                            isoGridSquare.getModData().rawget("lastWaterHour")
                        );
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset(
                            "planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":waterNeeded",
                            isoGridSquare.getModData().rawget("waterNeeded")
                        );
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset(
                            "planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":waterNeededMax",
                            isoGridSquare.getModData().rawget("waterNeededMax")
                        );
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset(
                            "planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":mildewLvl",
                            isoGridSquare.getModData().rawget("mildewLvl")
                        );
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset(
                            "planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":aphidLvl",
                            isoGridSquare.getModData().rawget("aphidLvl")
                        );
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset(
                            "planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":fliesLvl",
                            isoGridSquare.getModData().rawget("fliesLvl")
                        );
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset(
                            "planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":fertilizer",
                            isoGridSquare.getModData().rawget("fertilizer")
                        );
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset(
                            "planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":nextGrowing",
                            isoGridSquare.getModData().rawget("nextGrowing")
                        );
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset(
                            "planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":hasVegetable",
                            isoGridSquare.getModData().rawget("hasVegetable")
                        );
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset(
                            "planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":hasSeed",
                            isoGridSquare.getModData().rawget("hasSeed")
                        );
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset(
                            "planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":health", isoGridSquare.getModData().rawget("health")
                        );
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset(
                            "planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":badCare",
                            isoGridSquare.getModData().rawget("badCare")
                        );
                    zombie.GameTime.getInstance()
                        .getModData()
                        .rawset(
                            "planting:" + ((Double)isoGridSquare.getModData().rawget("id")).intValue() + ":state", isoGridSquare.getModData().rawget("state")
                        );
                    if (isoGridSquare.getModData().rawget("hoursElapsed") != null) {
                        zombie.GameTime.getInstance().getModData().rawset("hoursElapsed", isoGridSquare.getModData().rawget("hoursElapsed"));
                    }
                }

                LuaEventManager.triggerEvent("onLoadModDataFromServer", isoGridSquare);

                for (int int3 = 0; int3 < udpEngine.connections.size(); int3++) {
                    UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int3);
                    if (udpConnection0.RelevantTo((float)isoGridSquare.getX(), (float)isoGridSquare.getY())
                        && (udpConnection1 == null || udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID())) {
                        ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                        PacketTypes.PacketType.ReceiveModData.doPacket(byteBufferWriter);
                        byteBufferWriter.putInt(int0);
                        byteBufferWriter.putInt(int1);
                        byteBufferWriter.putInt(int2);

                        try {
                            isoGridSquare.getModData().save(byteBufferWriter.bb);
                        } catch (IOException iOException0) {
                            iOException0.printStackTrace();
                        }

                        PacketTypes.PacketType.ReceiveModData.send(udpConnection0);
                    }
                }
            } catch (IOException iOException1) {
                iOException1.printStackTrace();
            }
        }
    }

    static void receiveWeaponHit(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        IsoObject isoObject = getIsoObjectRefFromByteBuffer(byteBuffer);
        short _short = byteBuffer.getShort();
        String string = zombie.GameWindow.ReadStringUTF(byteBuffer);
        IsoPlayer isoPlayer = getPlayerFromConnection(udpConnection, _short);
        if (isoObject != null && isoPlayer != null) {
            InventoryItem inventoryItem = null;
            if (!string.isEmpty()) {
                inventoryItem = InventoryItemFactory.CreateItem(string);
                if (!(inventoryItem instanceof HandWeapon)) {
                    return;
                }
            }

            if (inventoryItem == null && !(isoObject instanceof IsoWindow)) {
                return;
            }

            int int0 = (int)isoObject.getX();
            int int1 = (int)isoObject.getY();
            int int2 = (int)isoObject.getZ();
            if (isoObject instanceof IsoDoor) {
                ((IsoDoor)isoObject).WeaponHit(isoPlayer, (HandWeapon)inventoryItem);
            } else if (isoObject instanceof IsoThumpable) {
                ((IsoThumpable)isoObject).WeaponHit(isoPlayer, (HandWeapon)inventoryItem);
            } else if (isoObject instanceof IsoWindow) {
                ((IsoWindow)isoObject).WeaponHit(isoPlayer, (HandWeapon)inventoryItem);
            } else if (isoObject instanceof IsoBarricade) {
                ((IsoBarricade)isoObject).WeaponHit(isoPlayer, (HandWeapon)inventoryItem);
            }

            if (isoObject.getObjectIndex() == -1) {
                LoggerManager.getLogger("map")
                    .write(
                        udpConnection.idStr
                            + " \""
                            + udpConnection.username
                            + "\" destroyed "
                            + (isoObject.getName() != null ? isoObject.getName() : isoObject.getObjectName())
                            + " with "
                            + (string.isEmpty() ? "BareHands" : string)
                            + " at "
                            + int0
                            + ","
                            + int1
                            + ","
                            + int2
                    );
            }
        }
    }

    private static void putIsoObjectRefToByteBuffer(IsoObject isoObject, ByteBuffer byteBuffer) {
        byteBuffer.putInt(isoObject.square.x);
        byteBuffer.putInt(isoObject.square.y);
        byteBuffer.putInt(isoObject.square.z);
        byteBuffer.put((byte)isoObject.square.getObjects().indexOf(isoObject));
    }

    private static IsoObject getIsoObjectRefFromByteBuffer(ByteBuffer byteBuffer) {
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        byte _byte = byteBuffer.get();
        IsoGridSquare isoGridSquare = ServerMap.instance.getGridSquare(int0, int1, int2);
        return isoGridSquare != null && _byte >= 0 && _byte < isoGridSquare.getObjects().size() ? isoGridSquare.getObjects().get(_byte) : null;
    }

    static void receiveDrink(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        byte _byte = byteBuffer.get();
        float _float = byteBuffer.getFloat();
        IsoPlayer isoPlayer = getPlayerFromConnection(udpConnection, _byte);
        if (isoPlayer != null) {
            isoPlayer.getStats().thirst -= _float;
            if (isoPlayer.getStats().thirst < 0.0F) {
                isoPlayer.getStats().thirst = 0.0F;
            }
        }
    }

    private static void process(ZomboidNetData zomboidNetData) {
        ByteBuffer byteBuffer = zomboidNetData.buffer;
        UdpConnection udpConnection = udpEngine.getActiveConnection(zomboidNetData.connection);

        try {
            switch (zomboidNetData.type) {
                default:
                    doZomboidDataInMainLoop(zomboidNetData);
            }
        } catch (Exception exception) {
            DebugLog.log(DebugType.Network, "Error with packet of type: " + zomboidNetData.type);
            exception.printStackTrace();
        }
    }

    static void receiveEatFood(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        byte _byte = byteBuffer.get();
        float _float = byteBuffer.getFloat();
        InventoryItem inventoryItem = null;

        try {
            inventoryItem = InventoryItem.loadItem(byteBuffer, 195);
        } catch (Exception exception) {
            exception.printStackTrace();
        }

        if (inventoryItem instanceof Food) {
            IsoPlayer isoPlayer = getPlayerFromConnection(udpConnection, _byte);
            if (isoPlayer != null) {
                isoPlayer.Eat(inventoryItem, _float);
            }
        }
    }

    static void receivePingFromClient(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
        long _long = byteBuffer.getLong();
        if (_long == -1L) {
            DebugLog.Multiplayer.warn("Player \"%s\" toggled lua debugger", udpConnection.username);
        } else {
            if (udpConnection.accessLevel != 32) {
                return;
            }

            PacketTypes.PacketType.PingFromClient.doPacket(byteBufferWriter);

            try {
                byteBufferWriter.putLong(_long);
                MPStatistics.write(udpConnection, byteBufferWriter.bb);
                PacketTypes.PacketType.PingFromClient.send(udpConnection);
                MPStatistics.requested();
            } catch (Exception exception) {
                udpConnection.cancelPacket();
            }
        }
    }

    static void receiveBandage(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        short _short = byteBuffer.getShort();
        IsoPlayer isoPlayer = (IsoPlayer)IDToPlayerMap.get(_short);
        if (isoPlayer != null) {
            int int0 = byteBuffer.getInt();
            boolean boolean0 = byteBuffer.get() == 1;
            float _float = byteBuffer.getFloat();
            boolean boolean1 = byteBuffer.get() == 1;
            String string = zombie.GameWindow.ReadStringUTF(byteBuffer);
            isoPlayer.getBodyDamage().SetBandaged(int0, boolean0, _float, boolean1, string);

            for (int int1 = 0; int1 < udpEngine.connections.size(); int1++) {
                UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int1);
                if (udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID()) {
                    ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                    PacketTypes.PacketType.Bandage.doPacket(byteBufferWriter);
                    byteBufferWriter.putShort(_short);
                    byteBufferWriter.putInt(int0);
                    byteBufferWriter.putBoolean(boolean0);
                    byteBufferWriter.putFloat(_float);
                    byteBufferWriter.putBoolean(boolean1);
                    zombie.GameWindow.WriteStringUTF(byteBufferWriter.bb, string);
                    PacketTypes.PacketType.Bandage.send(udpConnection0);
                }
            }
        }
    }

    static void receiveStitch(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        Stitch stitch = new Stitch();
        stitch.parse(byteBuffer, udpConnection0);
        if (stitch.isConsistent() && stitch.validate(udpConnection0)) {
            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()) {
                    ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                    PacketTypes.PacketType.Stitch.doPacket(byteBufferWriter);
                    stitch.write(byteBufferWriter);
                    PacketTypes.PacketType.Stitch.send(udpConnection1);
                }
            }
        }
    }

    @Deprecated
    static void receiveWoundInfection(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        short _short = byteBuffer.getShort();
        IsoPlayer isoPlayer = (IsoPlayer)IDToPlayerMap.get(_short);
        if (isoPlayer != null) {
            int int0 = byteBuffer.getInt();
            boolean _boolean = byteBuffer.get() == 1;
            isoPlayer.getBodyDamage().getBodyPart(BodyPartType.FromIndex(int0)).setInfectedWound(_boolean);

            for (int int1 = 0; int1 < udpEngine.connections.size(); int1++) {
                UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int1);
                if (udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID()) {
                    ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                    PacketTypes.PacketType.WoundInfection.doPacket(byteBufferWriter);
                    byteBufferWriter.putShort(_short);
                    byteBufferWriter.putInt(int0);
                    byteBufferWriter.putBoolean(_boolean);
                    PacketTypes.PacketType.WoundInfection.send(udpConnection0);
                }
            }
        }
    }

    static void receiveDisinfect(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        Disinfect disinfect = new Disinfect();
        disinfect.parse(byteBuffer, udpConnection0);
        if (disinfect.isConsistent() && disinfect.validate(udpConnection0)) {
            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()) {
                    ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                    PacketTypes.PacketType.Disinfect.doPacket(byteBufferWriter);
                    disinfect.write(byteBufferWriter);
                    PacketTypes.PacketType.Disinfect.send(udpConnection1);
                }
            }
        }
    }

    static void receiveSplint(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        short _short = byteBuffer.getShort();
        IsoPlayer isoPlayer = (IsoPlayer)IDToPlayerMap.get(_short);
        if (isoPlayer != null) {
            int int0 = byteBuffer.getInt();
            boolean _boolean = byteBuffer.get() == 1;
            String string = _boolean ? zombie.GameWindow.ReadStringUTF(byteBuffer) : null;
            float _float = _boolean ? byteBuffer.getFloat() : 0.0F;
            BodyPart bodyPart = isoPlayer.getBodyDamage().getBodyPart(BodyPartType.FromIndex(int0));
            bodyPart.setSplint(_boolean, _float);
            bodyPart.setSplintItem(string);

            for (int int1 = 0; int1 < udpEngine.connections.size(); int1++) {
                UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int1);
                if (udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID()) {
                    ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                    PacketTypes.PacketType.Splint.doPacket(byteBufferWriter);
                    byteBufferWriter.putShort(_short);
                    byteBufferWriter.putInt(int0);
                    byteBufferWriter.putBoolean(_boolean);
                    if (_boolean) {
                        byteBufferWriter.putUTF(string);
                        byteBufferWriter.putFloat(_float);
                    }

                    PacketTypes.PacketType.Splint.send(udpConnection0);
                }
            }
        }
    }

    static void receiveAdditionalPain(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        short _short = byteBuffer.getShort();
        IsoPlayer isoPlayer = (IsoPlayer)IDToPlayerMap.get(_short);
        if (isoPlayer != null) {
            int int0 = byteBuffer.getInt();
            float _float = byteBuffer.getFloat();
            BodyPart bodyPart = isoPlayer.getBodyDamage().getBodyPart(BodyPartType.FromIndex(int0));
            bodyPart.setAdditionalPain(bodyPart.getAdditionalPain() + _float);

            for (int int1 = 0; int1 < udpEngine.connections.size(); int1++) {
                UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int1);
                if (udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID()) {
                    ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                    PacketTypes.PacketType.AdditionalPain.doPacket(byteBufferWriter);
                    byteBufferWriter.putShort(_short);
                    byteBufferWriter.putInt(int0);
                    byteBufferWriter.putFloat(_float);
                    PacketTypes.PacketType.AdditionalPain.send(udpConnection0);
                }
            }
        }
    }

    static void receiveRemoveGlass(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        RemoveGlass removeGlass = new RemoveGlass();
        removeGlass.parse(byteBuffer, udpConnection0);
        if (removeGlass.isConsistent() && removeGlass.validate(udpConnection0)) {
            removeGlass.process();

            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()) {
                    ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                    PacketTypes.PacketType.RemoveGlass.doPacket(byteBufferWriter);
                    removeGlass.write(byteBufferWriter);
                    PacketTypes.PacketType.RemoveGlass.send(udpConnection1);
                }
            }
        }
    }

    static void receiveRemoveBullet(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        RemoveBullet removeBullet = new RemoveBullet();
        removeBullet.parse(byteBuffer, udpConnection0);
        if (removeBullet.isConsistent() && removeBullet.validate(udpConnection0)) {
            removeBullet.process();

            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()) {
                    ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                    PacketTypes.PacketType.RemoveBullet.doPacket(byteBufferWriter);
                    removeBullet.write(byteBufferWriter);
                    PacketTypes.PacketType.RemoveBullet.send(udpConnection1);
                }
            }
        }
    }

    static void receiveCleanBurn(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        CleanBurn cleanBurn = new CleanBurn();
        cleanBurn.parse(byteBuffer, udpConnection0);
        if (cleanBurn.isConsistent() && cleanBurn.validate(udpConnection0)) {
            cleanBurn.process();

            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()) {
                    ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                    PacketTypes.PacketType.CleanBurn.doPacket(byteBufferWriter);
                    cleanBurn.write(byteBufferWriter);
                    PacketTypes.PacketType.CleanBurn.send(udpConnection1);
                }
            }
        }
    }

    static void receiveBodyDamageUpdate(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        BodyDamageSync.instance.serverPacket(byteBuffer);
    }

    static void receiveReceiveCommand(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        String string = zombie.GameWindow.ReadString(byteBuffer);
        Object object = null;
        object = handleClientCommand(string.substring(1), udpConnection);
        if (object == null) {
            object = handleServerCommand(string.substring(1), udpConnection);
        }

        if (object == null) {
            object = "Unknown command " + string;
        }

        if (!string.substring(1).startsWith("roll") && !string.substring(1).startsWith("card")) {
            ChatServer.getInstance().sendMessageToServerChat(udpConnection, (String)object);
        } else {
            ChatServer.getInstance().sendMessageToServerChat(udpConnection, (String)object);
        }
    }

    private static String handleClientCommand(String string0, UdpConnection udpConnection) {
        if (string0 == null) {
            return null;
        } else {
            ArrayList arrayList = new ArrayList();
            Matcher matcher = Pattern.compile("([^\"]\\S*|\".*?\")\\s*").matcher(string0);

            while (matcher.find()) {
                arrayList.add(matcher.group(1).replace("\"", ""));
            }

            int int0 = arrayList.size();
            String[] string1 = (String[])arrayList.toArray(new String[int0]);
            String string2 = int0 > 0 ? string1[0].toLowerCase() : "";
            if (string2.equals("card")) {
                PlayWorldSoundServer("ChatDrawCard", false, getAnyPlayerFromConnection(udpConnection).getCurrentSquare(), 0.0F, 3.0F, 1.0F, false);
                return udpConnection.username + " drew " + ServerOptions.getRandomCard();
            } else if (string2.equals("roll")) {
                if (int0 != 2) {
                    return (String)ServerOptions.clientOptionsList.get("roll");
                } else {
                    int int1 = 0;

                    try {
                        int1 = Integer.parseInt(string1[1]);
                        PlayWorldSoundServer("ChatRollDice", false, getAnyPlayerFromConnection(udpConnection).getCurrentSquare(), 0.0F, 3.0F, 1.0F, false);
                        return udpConnection.username + " rolls a " + int1 + "-sided dice and obtains " + Rand.Next(int1);
                    } catch (Exception exception) {
                        return (String)ServerOptions.clientOptionsList.get("roll");
                    }
                }
            } else if (string2.equals("changepwd")) {
                if (int0 == 3) {
                    String string3 = string1[1];
                    String string4 = string1[2];

                    try {
                        return ServerWorldDatabase.instance.changePwd(udpConnection.username, string3.trim(), string4.trim());
                    } catch (SQLException sQLException) {
                        sQLException.printStackTrace();
                        return "A SQL error occured";
                    }
                } else {
                    return (String)ServerOptions.clientOptionsList.get("changepwd");
                }
            } else if (string2.equals("dragons")) {
                return "Sorry, you don't have the required materials.";
            } else if (string2.equals("dance")) {
                return "Stop kidding me...";
            } else if (string2.equals("safehouse")) {
                if (int0 != 2 || udpConnection == null) {
                    return (String)ServerOptions.clientOptionsList.get("safehouse");
                } else if (!ServerOptions.instance.PlayerSafehouse.getValue() && !ServerOptions.instance.AdminSafehouse.getValue()) {
                    return "Safehouses are disabled on this server.";
                } else if ("release".equals(string1[1])) {
                    SafeHouse safeHouse = SafeHouse.hasSafehouse(udpConnection.username);
                    if (safeHouse == null) {
                        return "You don't own a safehouse.";
                    } else if (!ServerOptions.instance.PlayerSafehouse.getValue()
                        && !"admin".equals(udpConnection.accessLevel)
                        && !"moderator".equals(udpConnection.accessLevel)) {
                        return "Only admin or moderator may release safehouses";
                    } else {
                        safeHouse.removeSafeHouse(null);
                        return "Safehouse released";
                    }
                } else {
                    return (String)ServerOptions.clientOptionsList.get("safehouse");
                }
            } else {
                return null;
            }
        }
    }

    public static void doZomboidDataInMainLoop(ZomboidNetData d) {
        synchronized (MainLoopNetDataHighPriorityQ) {
            MainLoopNetDataHighPriorityQ.add(d);
        }
    }

    static void receiveEquip(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        byte byte0 = byteBuffer.get();
        byte byte1 = byteBuffer.get();
        byte byte2 = byteBuffer.get();
        InventoryItem inventoryItem = null;
        IsoPlayer isoPlayer0 = getPlayerFromConnection(udpConnection0, byte0);
        if (byte2 == 1) {
            try {
                inventoryItem = InventoryItem.loadItem(byteBuffer, 195);
            } catch (Exception exception) {
                exception.printStackTrace();
            }

            if (inventoryItem == null) {
                LoggerManager.getLogger("user").write(udpConnection0.idStr + " equipped unknown item type");
                return;
            }
        }

        if (isoPlayer0 != null) {
            if (inventoryItem != null) {
                inventoryItem.setContainer(isoPlayer0.getInventory());
            }

            if (byte1 == 0) {
                isoPlayer0.setPrimaryHandItem(inventoryItem);
            } else {
                if (byte2 == 2) {
                    inventoryItem = isoPlayer0.getPrimaryHandItem();
                }

                isoPlayer0.setSecondaryHandItem(inventoryItem);
            }

            try {
                if (byte2 == 1 && inventoryItem != null && byteBuffer.get() == 1) {
                    inventoryItem.getVisual().load(byteBuffer, 195);
                }
            } catch (IOException iOException0) {
                iOException0.printStackTrace();
            }
        }

        if (isoPlayer0 != null) {
            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()) {
                    IsoPlayer isoPlayer1 = getAnyPlayerFromConnection(udpConnection1);
                    if (isoPlayer1 != null) {
                        ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                        PacketTypes.PacketType.Equip.doPacket(byteBufferWriter);
                        byteBufferWriter.putShort(isoPlayer0.OnlineID);
                        byteBufferWriter.putByte(byte1);
                        byteBufferWriter.putByte(byte2);
                        if (byte2 == 1) {
                            try {
                                inventoryItem.saveWithSize(byteBufferWriter.bb, false);
                                if (inventoryItem.getVisual() != null) {
                                    byteBufferWriter.bb.put((byte)1);
                                    inventoryItem.getVisual().save(byteBufferWriter.bb);
                                } else {
                                    byteBufferWriter.bb.put((byte)0);
                                }
                            } catch (IOException iOException1) {
                                iOException1.printStackTrace();
                            }
                        }

                        PacketTypes.PacketType.Equip.send(udpConnection1);
                    }
                }
            }
        }
    }

    static void receivePlayerConnect(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        receivePlayerConnect(byteBuffer, udpConnection, udpConnection.username);
        sendInitialWorldState(udpConnection);
    }

    static void receiveScoreboardUpdate(ByteBuffer var0, UdpConnection udpConnection0, short var2) {
        ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
        PacketTypes.PacketType.ScoreboardUpdate.doPacket(byteBufferWriter);
        ArrayList arrayList0 = new ArrayList();
        ArrayList arrayList1 = new ArrayList();
        ArrayList arrayList2 = new ArrayList();

        for (int int0 = 0; int0 < udpEngine.connections.size(); int0++) {
            UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(int0);
            if (udpConnection1.isFullyConnected()) {
                for (int int1 = 0; int1 < 4; int1++) {
                    if (udpConnection1.usernames[int1] != null) {
                        arrayList0.add(udpConnection1.usernames[int1]);
                        IsoPlayer isoPlayer = getPlayerByRealUserName(udpConnection1.usernames[int1]);
                        if (isoPlayer != null) {
                            arrayList1.add(isoPlayer.getDisplayName());
                        } else {
                            String string = ServerWorldDatabase.instance.getDisplayName(udpConnection1.usernames[int1]);
                            arrayList1.add(string == null ? udpConnection1.usernames[int1] : string);
                        }

                        if (SteamUtils.isSteamModeEnabled()) {
                            arrayList2.add(udpConnection1.steamID);
                        }
                    }
                }
            }
        }

        byteBufferWriter.putInt(arrayList0.size());

        for (int int2 = 0; int2 < arrayList0.size(); int2++) {
            byteBufferWriter.putUTF((String)arrayList0.get(int2));
            byteBufferWriter.putUTF((String)arrayList1.get(int2));
            if (SteamUtils.isSteamModeEnabled()) {
                byteBufferWriter.putLong((Long)arrayList2.get(int2));
            }
        }

        PacketTypes.PacketType.ScoreboardUpdate.send(udpConnection0);
    }

    static void receiveStopSound(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        StopSoundPacket stopSoundPacket = new StopSoundPacket();
        stopSoundPacket.parse(byteBuffer, udpConnection0);

        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
            if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID() && udpConnection1.isFullyConnected()) {
                ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                PacketTypes.PacketType.StopSound.doPacket(byteBufferWriter);
                stopSoundPacket.write(byteBufferWriter);
                PacketTypes.PacketType.StopSound.send(udpConnection1);
            }
        }
    }

    static void receivePlaySound(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        PlaySoundPacket playSoundPacket = new PlaySoundPacket();
        playSoundPacket.parse(byteBuffer, udpConnection0);
        IsoMovingObject isoMovingObject = playSoundPacket.getMovingObject();
        if (playSoundPacket.isConsistent()) {
            int int0 = 70;
            GameSound gameSound = zombie.GameSounds.getSound(playSoundPacket.getName());
            if (gameSound != null) {
                for (int int1 = 0; int1 < gameSound.clips.size(); int1++) {
                    GameSoundClip gameSoundClip = (GameSoundClip)gameSound.clips.get(int1);
                    if (gameSoundClip.hasMaxDistance()) {
                        int0 = Math.max(int0, (int)gameSoundClip.distanceMax);
                    }
                }
            }

            for (int int2 = 0; int2 < udpEngine.connections.size(); int2++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(int2);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID() && udpConnection1.isFullyConnected()) {
                    IsoPlayer isoPlayer = getAnyPlayerFromConnection(udpConnection1);
                    if (isoPlayer != null
                        && (isoMovingObject == null || udpConnection1.RelevantTo(isoMovingObject.getX(), isoMovingObject.getY(), (float)int0))) {
                        ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                        PacketTypes.PacketType.PlaySound.doPacket(byteBufferWriter);
                        playSoundPacket.write(byteBufferWriter);
                        PacketTypes.PacketType.PlaySound.send(udpConnection1);
                    }
                }
            }
        }
    }

    static void receivePlayWorldSound(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        PlayWorldSoundPacket playWorldSoundPacket = new PlayWorldSoundPacket();
        playWorldSoundPacket.parse(byteBuffer, udpConnection0);
        if (playWorldSoundPacket.isConsistent()) {
            int int0 = 70;
            GameSound gameSound = zombie.GameSounds.getSound(playWorldSoundPacket.getName());
            if (gameSound != null) {
                for (int int1 = 0; int1 < gameSound.clips.size(); int1++) {
                    GameSoundClip gameSoundClip = (GameSoundClip)gameSound.clips.get(int1);
                    if (gameSoundClip.hasMaxDistance()) {
                        int0 = Math.max(int0, (int)gameSoundClip.distanceMax);
                    }
                }
            }

            for (int int2 = 0; int2 < udpEngine.connections.size(); int2++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(int2);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID() && udpConnection1.isFullyConnected()) {
                    IsoPlayer isoPlayer = getAnyPlayerFromConnection(udpConnection1);
                    if (isoPlayer != null && udpConnection1.RelevantTo((float)playWorldSoundPacket.getX(), (float)playWorldSoundPacket.getY(), (float)int0)) {
                        ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                        PacketTypes.PacketType.PlayWorldSound.doPacket(byteBufferWriter);
                        playWorldSoundPacket.write(byteBufferWriter);
                        PacketTypes.PacketType.PlayWorldSound.send(udpConnection1);
                    }
                }
            }
        }
    }

    private static void PlayWorldSound(String string, IsoGridSquare isoGridSquare, float _float) {
        if (bServer && isoGridSquare != null) {
            int int0 = isoGridSquare.getX();
            int int1 = isoGridSquare.getY();
            int int2 = isoGridSquare.getZ();
            PlayWorldSoundPacket playWorldSoundPacket = new PlayWorldSoundPacket();
            playWorldSoundPacket.set(string, int0, int1, (byte)int2);
            DebugLog.log(DebugType.Sound, "sending " + playWorldSoundPacket.getDescription() + " radius=" + _float);

            for (int int3 = 0; int3 < udpEngine.connections.size(); int3++) {
                UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(int3);
                IsoPlayer isoPlayer = getAnyPlayerFromConnection(udpConnection);
                if (isoPlayer != null && udpConnection.RelevantTo((float)int0, (float)int1, _float * 2.0F)) {
                    ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                    PacketTypes.PacketType.PlayWorldSound.doPacket(byteBufferWriter);
                    playWorldSoundPacket.write(byteBufferWriter);
                    PacketTypes.PacketType.PlayWorldSound.send(udpConnection);
                }
            }
        }
    }

    public static void PlayWorldSoundServer(String name, boolean loop, IsoGridSquare source, float pitchVar, float radius, float maxGain, boolean ignoreOutside) {
        PlayWorldSound(name, source, radius);
    }

    public static void PlayWorldSoundServer(
        IsoGameCharacter character, String name, boolean loop, IsoGridSquare source, float pitchVar, float radius, float maxGain, boolean ignoreOutside
    ) {
        if (character == null || !character.isInvisible() || DebugOptions.instance.Character.Debug.PlaySoundWhenInvisible.getValue()) {
            PlayWorldSound(name, source, radius);
        }
    }

    public static void PlayWorldSoundWavServer(
        String name, boolean loop, IsoGridSquare source, float pitchVar, float radius, float maxGain, boolean ignoreOutside
    ) {
        PlayWorldSound(name, source, radius);
    }

    public static void PlaySoundAtEveryPlayer(String name, int x, int y, int z) {
        PlaySoundAtEveryPlayer(name, x, y, z, false);
    }

    public static void PlaySoundAtEveryPlayer(String name) {
        PlaySoundAtEveryPlayer(name, -1, -1, -1, true);
    }

    public static void PlaySoundAtEveryPlayer(String name, int x, int y, int z, boolean usePlrCoords) {
        if (bServer) {
            if (usePlrCoords) {
                DebugLog.log(DebugType.Sound, "sound: sending " + name + " at every player (using player location)");
            } else {
                DebugLog.log(DebugType.Sound, "sound: sending " + name + " at every player location x=" + x + " y=" + y);
            }

            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
                IsoPlayer isoPlayer = getAnyPlayerFromConnection(udpConnection);
                if (isoPlayer != null && !isoPlayer.isDeaf()) {
                    if (usePlrCoords) {
                        x = (int)isoPlayer.getX();
                        y = (int)isoPlayer.getY();
                        z = (int)isoPlayer.getZ();
                    }

                    ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                    PacketTypes.PacketType.PlaySoundEveryPlayer.doPacket(byteBufferWriter);
                    byteBufferWriter.putUTF(name);
                    byteBufferWriter.putInt(x);
                    byteBufferWriter.putInt(y);
                    byteBufferWriter.putInt(z);
                    PacketTypes.PacketType.PlaySoundEveryPlayer.send(udpConnection);
                }
            }
        }
    }

    public static void sendZombieSound(IsoZombie.ZombieSound sound, IsoZombie zombie) {
        float _float = (float)sound.radius();
        DebugLog.log(DebugType.Sound, "sound: sending zombie sound " + sound);

        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            if (udpConnection.isFullyConnected() && udpConnection.RelevantTo(zombie.getX(), zombie.getY(), _float)) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.ZombieSound.doPacket(byteBufferWriter);
                byteBufferWriter.putShort(zombie.OnlineID);
                byteBufferWriter.putByte((byte)sound.ordinal());
                PacketTypes.PacketType.ZombieSound.send(udpConnection);
            }
        }
    }

    static void receiveZombieHelmetFalling(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        byte _byte = byteBuffer.get();
        short _short = byteBuffer.getShort();
        String string = zombie.GameWindow.ReadString(byteBuffer);
        IsoZombie isoZombie = ServerMap.instance.ZombieMap.get(_short);
        IsoPlayer isoPlayer0 = getPlayerFromConnection(udpConnection0, _byte);
        if (isoPlayer0 != null && isoZombie != null) {
            isoZombie.serverRemoveItemFromZombie(string);

            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()) {
                    IsoPlayer isoPlayer1 = getAnyPlayerFromConnection(udpConnection0);
                    if (isoPlayer1 != null) {
                        try {
                            ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                            PacketTypes.PacketType.ZombieHelmetFalling.doPacket(byteBufferWriter);
                            byteBufferWriter.putShort(_short);
                            byteBufferWriter.putUTF(string);
                            PacketTypes.PacketType.ZombieHelmetFalling.send(udpConnection1);
                        } catch (Throwable throwable) {
                            udpConnection0.cancelPacket();
                            ExceptionLogger.logException(throwable);
                        }
                    }
                }
            }
        }
    }

    static void receivePlayerAttachedItem(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        byte _byte = byteBuffer.get();
        String string0 = zombie.GameWindow.ReadString(byteBuffer);
        boolean _boolean = byteBuffer.get() == 1;
        InventoryItem inventoryItem = null;
        if (_boolean) {
            String string1 = zombie.GameWindow.ReadString(byteBuffer);
            inventoryItem = InventoryItemFactory.CreateItem(string1);
            if (inventoryItem == null) {
                return;
            }
        }

        IsoPlayer isoPlayer0 = getPlayerFromConnection(udpConnection0, _byte);
        if (isoPlayer0 != null) {
            isoPlayer0.setAttachedItem(string0, inventoryItem);

            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()) {
                    IsoPlayer isoPlayer1 = getAnyPlayerFromConnection(udpConnection0);
                    if (isoPlayer1 != null) {
                        try {
                            ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                            PacketTypes.PacketType.PlayerAttachedItem.doPacket(byteBufferWriter);
                            byteBufferWriter.putShort(isoPlayer0.OnlineID);
                            zombie.GameWindow.WriteString(byteBufferWriter.bb, string0);
                            byteBufferWriter.putByte((byte)(_boolean ? 1 : 0));
                            if (_boolean) {
                                zombie.GameWindow.WriteString(byteBufferWriter.bb, inventoryItem.getFullType());
                            }

                            PacketTypes.PacketType.PlayerAttachedItem.send(udpConnection1);
                        } catch (Throwable throwable) {
                            udpConnection0.cancelPacket();
                            ExceptionLogger.logException(throwable);
                        }
                    }
                }
            }
        }
    }

    static void receiveSyncClothing(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        SyncClothingPacket syncClothingPacket = new SyncClothingPacket();
        syncClothingPacket.parse(byteBuffer, udpConnection0);
        if (syncClothingPacket.isConsistent()) {
            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()) {
                    IsoPlayer isoPlayer = getAnyPlayerFromConnection(udpConnection0);
                    if (isoPlayer != null) {
                        ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                        PacketTypes.PacketType.SyncClothing.doPacket(byteBufferWriter);
                        syncClothingPacket.write(byteBufferWriter);
                        PacketTypes.PacketType.SyncClothing.send(udpConnection1);
                    }
                }
            }
        }
    }

    static void receiveHumanVisual(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        short _short = byteBuffer.getShort();
        IsoPlayer isoPlayer0 = (IsoPlayer)IDToPlayerMap.get(_short);
        if (isoPlayer0 != null) {
            if (!udpConnection0.havePlayer(isoPlayer0)) {
                DebugLog.Network.warn("User " + udpConnection0.username + " sent HumanVisual packet for non owned player #" + isoPlayer0.OnlineID);
            } else {
                try {
                    isoPlayer0.getHumanVisual().load(byteBuffer, 195);
                } catch (Throwable throwable0) {
                    ExceptionLogger.logException(throwable0);
                    return;
                }

                for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                    UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
                    if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()) {
                        IsoPlayer isoPlayer1 = getAnyPlayerFromConnection(udpConnection1);
                        if (isoPlayer1 != null) {
                            ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                            PacketTypes.PacketType.HumanVisual.doPacket(byteBufferWriter);

                            try {
                                byteBufferWriter.putShort(isoPlayer0.OnlineID);
                                isoPlayer0.getHumanVisual().save(byteBufferWriter.bb);
                                PacketTypes.PacketType.HumanVisual.send(udpConnection1);
                            } catch (Throwable throwable1) {
                                udpConnection1.cancelPacket();
                                ExceptionLogger.logException(throwable1);
                            }
                        }
                    }
                }
            }
        }
    }

    public static void initClientCommandFilter() {
        String string0 = ServerOptions.getInstance().ClientCommandFilter.getValue();
        ccFilters.clear();
        String[] string1 = string0.split(";");

        for (String string2 : string1) {
            if (!string2.isEmpty() && string2.contains(".") && (string2.startsWith("+") || string2.startsWith("-"))) {
                String[] string3 = string2.split("\\.");
                if (string3.length == 2) {
                    String string4 = string3[0].substring(1);
                    String string5 = string3[1];
                    GameServer.CCFilter cCFilter = new GameServer.CCFilter();
                    cCFilter.command = string5;
                    cCFilter.allow = string3[0].startsWith("+");
                    cCFilter.next = (GameServer.CCFilter)ccFilters.get(string4);
                    ccFilters.put(string4, cCFilter);
                }
            }
        }
    }

    static void receiveClientCommand(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        byte _byte = byteBuffer.get();
        String string0 = zombie.GameWindow.ReadString(byteBuffer);
        String string1 = zombie.GameWindow.ReadString(byteBuffer);
        boolean _boolean = byteBuffer.get() == 1;
        KahluaTable kahluaTable = null;
        if (_boolean) {
            kahluaTable = LuaManager.platform.newTable();

            try {
                TableNetworkUtils.load(kahluaTable, byteBuffer);
            } catch (Exception exception) {
                exception.printStackTrace();
                return;
            }
        }

        IsoPlayer isoPlayer = getPlayerFromConnection(udpConnection, _byte);
        if (_byte == -1) {
            isoPlayer = getAnyPlayerFromConnection(udpConnection);
        }

        if (isoPlayer == null) {
            DebugLog.log("receiveClientCommand: player is null");
        } else {
            GameServer.CCFilter cCFilter = (GameServer.CCFilter)ccFilters.get(string0);
            if (cCFilter == null || cCFilter.passes(string1)) {
                LoggerManager.getLogger("cmd")
                    .write(
                        udpConnection.idStr
                            + " \""
                            + isoPlayer.username
                            + "\" "
                            + string0
                            + "."
                            + string1
                            + " @ "
                            + (int)isoPlayer.getX()
                            + ","
                            + (int)isoPlayer.getY()
                            + ","
                            + (int)isoPlayer.getZ()
                    );
            }

            if (!"vehicle".equals(string0)
                || !"remove".equals(string1)
                || Core.bDebug
                || PlayerType.isPrivileged(udpConnection.accessLevel)
                || isoPlayer.networkAI.isDismantleAllowed()) {
                LuaEventManager.triggerEvent("OnClientCommand", string0, string1, isoPlayer, kahluaTable);
            }
        }
    }

    static void receiveGlobalObjects(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        byte _byte = byteBuffer.get();
        IsoPlayer isoPlayer = getPlayerFromConnection(udpConnection, _byte);
        if (_byte == -1) {
            isoPlayer = getAnyPlayerFromConnection(udpConnection);
        }

        if (isoPlayer == null) {
            DebugLog.log("receiveGlobalObjects: player is null");
        } else {
            SGlobalObjectNetwork.receive(byteBuffer, isoPlayer);
        }
    }

    public static IsoPlayer getAnyPlayerFromConnection(UdpConnection connection) {
        for (int _int = 0; _int < 4; _int++) {
            if (connection.players[_int] != null) {
                return connection.players[_int];
            }
        }

        return null;
    }

    public static IsoPlayer getPlayerFromConnection(UdpConnection connection, int playerIndex) {
        return playerIndex >= 0 && playerIndex < 4 ? connection.players[playerIndex] : null;
    }

    public static IsoPlayer getPlayerByRealUserName(String username) {
        for (int int0 = 0; int0 < udpEngine.connections.size(); int0++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(int0);

            for (int int1 = 0; int1 < 4; int1++) {
                IsoPlayer isoPlayer = udpConnection.players[int1];
                if (isoPlayer != null && isoPlayer.username.equals(username)) {
                    return isoPlayer;
                }
            }
        }

        return null;
    }

    public static IsoPlayer getPlayerByUserName(String username) {
        for (int int0 = 0; int0 < udpEngine.connections.size(); int0++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(int0);

            for (int int1 = 0; int1 < 4; int1++) {
                IsoPlayer isoPlayer = udpConnection.players[int1];
                if (isoPlayer != null && (isoPlayer.getDisplayName().equals(username) || isoPlayer.getUsername().equals(username))) {
                    return isoPlayer;
                }
            }
        }

        return null;
    }

    public static IsoPlayer getPlayerByUserNameForCommand(String username) {
        for (int int0 = 0; int0 < udpEngine.connections.size(); int0++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(int0);

            for (int int1 = 0; int1 < 4; int1++) {
                IsoPlayer isoPlayer = udpConnection.players[int1];
                if (isoPlayer != null
                    && (
                        isoPlayer.getDisplayName().toLowerCase().equals(username.toLowerCase())
                            || isoPlayer.getDisplayName().toLowerCase().startsWith(username.toLowerCase())
                    )) {
                    return isoPlayer;
                }
            }
        }

        return null;
    }

    public static UdpConnection getConnectionByPlayerOnlineID(short onlineID) {
        return udpEngine.getActiveConnection((Long)IDToAddressMap.get(onlineID));
    }

    public static UdpConnection getConnectionFromPlayer(IsoPlayer player) {
        Long _long = (Long)PlayerToAddressMap.get(player);
        return _long == null ? null : udpEngine.getActiveConnection(_long);
    }

    static void receiveRemoveBlood(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        boolean _boolean = byteBuffer.get() == 1;
        IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare(int0, int1, int2);
        if (isoGridSquare != null) {
            isoGridSquare.removeBlood(false, _boolean);

            for (int int3 = 0; int3 < udpEngine.connections.size(); int3++) {
                UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int3);
                if (udpConnection0 != udpConnection1 && udpConnection0.RelevantTo((float)int0, (float)int1)) {
                    ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                    PacketTypes.PacketType.RemoveBlood.doPacket(byteBufferWriter);
                    byteBufferWriter.putInt(int0);
                    byteBufferWriter.putInt(int1);
                    byteBufferWriter.putInt(int2);
                    byteBufferWriter.putBoolean(_boolean);
                    PacketTypes.PacketType.RemoveBlood.send(udpConnection0);
                }
            }
        }
    }

    public static void sendAddItemToContainer(ItemContainer container, InventoryItem item) {
        Object object = container.getParent();
        if (container.getContainingItem() != null && container.getContainingItem().getWorldItem() != null) {
            object = container.getContainingItem().getWorldItem();
        }

        if (object == null) {
            DebugLog.General.error("container has no parent object");
        } else {
            IsoGridSquare isoGridSquare = ((IsoObject)object).getSquare();
            if (isoGridSquare == null) {
                DebugLog.General.error("container parent object has no square");
            } else {
                for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                    UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
                    if (udpConnection.RelevantTo((float)isoGridSquare.x, (float)isoGridSquare.y)) {
                        ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                        PacketTypes.PacketType.AddInventoryItemToContainer.doPacket(byteBufferWriter);
                        if (object instanceof IsoDeadBody) {
                            byteBufferWriter.putShort((short)0);
                            byteBufferWriter.putInt(((IsoObject)object).square.getX());
                            byteBufferWriter.putInt(((IsoObject)object).square.getY());
                            byteBufferWriter.putInt(((IsoObject)object).square.getZ());
                            byteBufferWriter.putByte((byte)((IsoObject)object).getStaticMovingObjectIndex());
                        } else if (object instanceof IsoWorldInventoryObject) {
                            byteBufferWriter.putShort((short)1);
                            byteBufferWriter.putInt(((IsoObject)object).square.getX());
                            byteBufferWriter.putInt(((IsoObject)object).square.getY());
                            byteBufferWriter.putInt(((IsoObject)object).square.getZ());
                            byteBufferWriter.putInt(((IsoWorldInventoryObject)object).getItem().id);
                        } else if (object instanceof BaseVehicle) {
                            byteBufferWriter.putShort((short)3);
                            byteBufferWriter.putInt(((IsoObject)object).square.getX());
                            byteBufferWriter.putInt(((IsoObject)object).square.getY());
                            byteBufferWriter.putInt(((IsoObject)object).square.getZ());
                            byteBufferWriter.putShort(((BaseVehicle)object).VehicleID);
                            byteBufferWriter.putByte((byte)container.vehiclePart.getIndex());
                        } else {
                            byteBufferWriter.putShort((short)2);
                            byteBufferWriter.putInt(((IsoObject)object).square.getX());
                            byteBufferWriter.putInt(((IsoObject)object).square.getY());
                            byteBufferWriter.putInt(((IsoObject)object).square.getZ());
                            byteBufferWriter.putByte((byte)((IsoObject)object).square.getObjects().indexOf(object));
                            byteBufferWriter.putByte((byte)((IsoObject)object).getContainerIndex(container));
                        }

                        try {
                            CompressIdenticalItems.save(byteBufferWriter.bb, item);
                        } catch (Exception exception) {
                            exception.printStackTrace();
                        }

                        PacketTypes.PacketType.AddInventoryItemToContainer.send(udpConnection);
                    }
                }
            }
        }
    }

    public static void sendRemoveItemFromContainer(ItemContainer container, InventoryItem item) {
        Object object = container.getParent();
        if (container.getContainingItem() != null && container.getContainingItem().getWorldItem() != null) {
            object = container.getContainingItem().getWorldItem();
        }

        if (object == null) {
            DebugLog.log("sendRemoveItemFromContainer: o is null");
        } else {
            IsoGridSquare isoGridSquare = ((IsoObject)object).getSquare();
            if (isoGridSquare == null) {
                DebugLog.log("sendRemoveItemFromContainer: square is null");
            } else {
                for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                    UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
                    if (udpConnection.RelevantTo((float)isoGridSquare.x, (float)isoGridSquare.y)) {
                        ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                        PacketTypes.PacketType.RemoveInventoryItemFromContainer.doPacket(byteBufferWriter);
                        if (object instanceof IsoDeadBody) {
                            byteBufferWriter.putShort((short)0);
                            byteBufferWriter.putInt(((IsoObject)object).square.getX());
                            byteBufferWriter.putInt(((IsoObject)object).square.getY());
                            byteBufferWriter.putInt(((IsoObject)object).square.getZ());
                            byteBufferWriter.putByte((byte)((IsoObject)object).getStaticMovingObjectIndex());
                            byteBufferWriter.putInt(1);
                            byteBufferWriter.putInt(item.id);
                        } else if (object instanceof IsoWorldInventoryObject) {
                            byteBufferWriter.putShort((short)1);
                            byteBufferWriter.putInt(((IsoObject)object).square.getX());
                            byteBufferWriter.putInt(((IsoObject)object).square.getY());
                            byteBufferWriter.putInt(((IsoObject)object).square.getZ());
                            byteBufferWriter.putInt(((IsoWorldInventoryObject)object).getItem().id);
                            byteBufferWriter.putInt(1);
                            byteBufferWriter.putInt(item.id);
                        } else if (object instanceof BaseVehicle) {
                            byteBufferWriter.putShort((short)3);
                            byteBufferWriter.putInt(((IsoObject)object).square.getX());
                            byteBufferWriter.putInt(((IsoObject)object).square.getY());
                            byteBufferWriter.putInt(((IsoObject)object).square.getZ());
                            byteBufferWriter.putShort(((BaseVehicle)object).VehicleID);
                            byteBufferWriter.putByte((byte)container.vehiclePart.getIndex());
                            byteBufferWriter.putInt(1);
                            byteBufferWriter.putInt(item.id);
                        } else {
                            byteBufferWriter.putShort((short)2);
                            byteBufferWriter.putInt(((IsoObject)object).square.getX());
                            byteBufferWriter.putInt(((IsoObject)object).square.getY());
                            byteBufferWriter.putInt(((IsoObject)object).square.getZ());
                            byteBufferWriter.putByte((byte)((IsoObject)object).square.getObjects().indexOf(object));
                            byteBufferWriter.putByte((byte)((IsoObject)object).getContainerIndex(container));
                            byteBufferWriter.putInt(1);
                            byteBufferWriter.putInt(item.id);
                        }

                        PacketTypes.PacketType.RemoveInventoryItemFromContainer.send(udpConnection);
                    }
                }
            }
        }
    }

    static void receiveRemoveInventoryItemFromContainer(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        alreadyRemoved.clear();
        ByteBufferReader byteBufferReader = new ByteBufferReader(byteBuffer);
        short short0 = byteBufferReader.getShort();
        int int0 = byteBufferReader.getInt();
        int int1 = byteBufferReader.getInt();
        int int2 = byteBufferReader.getInt();
        IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare(int0, int1, int2);
        if (isoGridSquare == null) {
            isoGridSquare = ServerMap.instance.getGridSquare(int0, int1, int2);
        }

        HashSet hashSet = new HashSet();
        boolean _boolean = false;
        int int3 = 0;
        if (short0 == 0) {
            byte byte0 = byteBufferReader.getByte();
            int3 = byteBuffer.getInt();
            if (isoGridSquare != null && byte0 >= 0 && byte0 < isoGridSquare.getStaticMovingObjects().size()) {
                IsoObject isoObject0 = (IsoObject)isoGridSquare.getStaticMovingObjects().get(byte0);
                if (isoObject0 != null && isoObject0.getContainer() != null) {
                    for (int int4 = 0; int4 < int3; int4++) {
                        int int5 = byteBufferReader.getInt();
                        InventoryItem inventoryItem0 = isoObject0.getContainer().getItemWithID(int5);
                        if (inventoryItem0 == null) {
                            alreadyRemoved.add(int5);
                        } else {
                            isoObject0.getContainer().Remove(inventoryItem0);
                            _boolean = true;
                            hashSet.add(inventoryItem0.getFullType());
                        }
                    }

                    isoObject0.getContainer().setExplored(true);
                    isoObject0.getContainer().setHasBeenLooted(true);
                }
            }
        } else if (short0 == 1) {
            if (isoGridSquare != null) {
                int int6 = byteBufferReader.getInt();
                int3 = byteBuffer.getInt();
                ItemContainer itemContainer0 = null;

                for (int int7 = 0; int7 < isoGridSquare.getWorldObjects().size(); int7++) {
                    IsoWorldInventoryObject isoWorldInventoryObject = (IsoWorldInventoryObject)isoGridSquare.getWorldObjects().get(int7);
                    if (isoWorldInventoryObject != null
                        && isoWorldInventoryObject.getItem() instanceof InventoryContainer
                        && isoWorldInventoryObject.getItem().id == int6) {
                        itemContainer0 = ((InventoryContainer)isoWorldInventoryObject.getItem()).getInventory();
                        break;
                    }
                }

                if (itemContainer0 != null) {
                    for (int int8 = 0; int8 < int3; int8++) {
                        int int9 = byteBufferReader.getInt();
                        InventoryItem inventoryItem1 = itemContainer0.getItemWithID(int9);
                        if (inventoryItem1 == null) {
                            alreadyRemoved.add(int9);
                        } else {
                            itemContainer0.Remove(inventoryItem1);
                            hashSet.add(inventoryItem1.getFullType());
                        }
                    }

                    itemContainer0.setExplored(true);
                    itemContainer0.setHasBeenLooted(true);
                }
            }
        } else if (short0 == 2) {
            byte byte1 = byteBufferReader.getByte();
            byte byte2 = byteBufferReader.getByte();
            int3 = byteBuffer.getInt();
            if (isoGridSquare != null && byte1 >= 0 && byte1 < isoGridSquare.getObjects().size()) {
                IsoObject isoObject1 = isoGridSquare.getObjects().get(byte1);
                ItemContainer itemContainer1 = isoObject1 != null ? isoObject1.getContainerByIndex(byte2) : null;
                if (itemContainer1 != null) {
                    for (int int10 = 0; int10 < int3; int10++) {
                        int int11 = byteBufferReader.getInt();
                        InventoryItem inventoryItem2 = itemContainer1.getItemWithID(int11);
                        if (inventoryItem2 == null) {
                            alreadyRemoved.add(int11);
                        } else {
                            itemContainer1.Remove(inventoryItem2);
                            itemContainer1.setExplored(true);
                            itemContainer1.setHasBeenLooted(true);
                            _boolean = true;
                            hashSet.add(inventoryItem2.getFullType());
                        }
                    }

                    LuaManager.updateOverlaySprite(isoObject1);
                }
            }
        } else if (short0 == 3) {
            short short1 = byteBufferReader.getShort();
            byte byte3 = byteBufferReader.getByte();
            int3 = byteBuffer.getInt();
            BaseVehicle baseVehicle = VehicleManager.instance.getVehicleByID(short1);
            if (baseVehicle != null) {
                VehiclePart vehiclePart = baseVehicle == null ? null : baseVehicle.getPartByIndex(byte3);
                ItemContainer itemContainer2 = vehiclePart == null ? null : vehiclePart.getItemContainer();
                if (itemContainer2 != null) {
                    for (int int12 = 0; int12 < int3; int12++) {
                        int int13 = byteBufferReader.getInt();
                        InventoryItem inventoryItem3 = itemContainer2.getItemWithID(int13);
                        if (inventoryItem3 == null) {
                            alreadyRemoved.add(int13);
                        } else {
                            itemContainer2.Remove(inventoryItem3);
                            itemContainer2.setExplored(true);
                            itemContainer2.setHasBeenLooted(true);
                            _boolean = true;
                            hashSet.add(inventoryItem3.getFullType());
                        }
                    }
                }
            }
        }

        for (int int14 = 0; int14 < udpEngine.connections.size(); int14++) {
            UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int14);
            if (udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID()
                && isoGridSquare != null
                && udpConnection0.RelevantTo((float)isoGridSquare.x, (float)isoGridSquare.y)) {
                byteBuffer.rewind();
                ByteBufferWriter byteBufferWriter0 = udpConnection0.startPacket();
                PacketTypes.PacketType.RemoveInventoryItemFromContainer.doPacket(byteBufferWriter0);
                byteBufferWriter0.bb.put(byteBuffer);
                PacketTypes.PacketType.RemoveInventoryItemFromContainer.send(udpConnection0);
            }
        }

        if (!alreadyRemoved.isEmpty()) {
            ByteBufferWriter byteBufferWriter1 = udpConnection1.startPacket();
            PacketTypes.PacketType.RemoveContestedItemsFromInventory.doPacket(byteBufferWriter1);
            byteBufferWriter1.putInt(alreadyRemoved.size());

            for (int int15 = 0; int15 < alreadyRemoved.size(); int15++) {
                byteBufferWriter1.putInt((Integer)alreadyRemoved.get(int15));
            }

            PacketTypes.PacketType.RemoveContestedItemsFromInventory.send(udpConnection1);
        }

        alreadyRemoved.clear();
        LoggerManager.getLogger("item")
            .write(
                udpConnection1.idStr
                    + " \""
                    + udpConnection1.username
                    + "\" container -"
                    + int3
                    + " "
                    + int0
                    + ","
                    + int1
                    + ","
                    + int2
                    + " "
                    + hashSet.toString()
            );
    }

    private static void readItemStats(ByteBuffer byteBuffer, InventoryItem inventoryItem) {
        int _int = byteBuffer.getInt();
        float _float = byteBuffer.getFloat();
        boolean _boolean = byteBuffer.get() == 1;
        inventoryItem.setUses(_int);
        if (inventoryItem instanceof DrainableComboItem) {
            ((DrainableComboItem)inventoryItem).setDelta(_float);
            ((DrainableComboItem)inventoryItem).updateWeight();
        }

        if (_boolean && inventoryItem instanceof Food food) {
            food.setHungChange(byteBuffer.getFloat());
            food.setCalories(byteBuffer.getFloat());
            food.setCarbohydrates(byteBuffer.getFloat());
            food.setLipids(byteBuffer.getFloat());
            food.setProteins(byteBuffer.getFloat());
            food.setThirstChange(byteBuffer.getFloat());
            food.setFluReduction(byteBuffer.getInt());
            food.setPainReduction(byteBuffer.getFloat());
            food.setEndChange(byteBuffer.getFloat());
            food.setReduceFoodSickness(byteBuffer.getInt());
            food.setStressChange(byteBuffer.getFloat());
            food.setFatigueChange(byteBuffer.getFloat());
        }
    }

    static void receiveItemStats(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        short short0 = byteBuffer.getShort();
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare(int0, int1, int2);
        switch (short0) {
            case 0:
                byte byte3 = byteBuffer.get();
                int int5 = byteBuffer.getInt();
                if (isoGridSquare != null && byte3 >= 0 && byte3 < isoGridSquare.getStaticMovingObjects().size()) {
                    IsoMovingObject isoMovingObject = (IsoMovingObject)isoGridSquare.getStaticMovingObjects().get(byte3);
                    ItemContainer itemContainer2 = isoMovingObject.getContainer();
                    if (itemContainer2 != null) {
                        InventoryItem inventoryItem2 = itemContainer2.getItemWithID(int5);
                        if (inventoryItem2 != null) {
                            readItemStats(byteBuffer, inventoryItem2);
                        }
                    }
                }
                break;
            case 1:
                int int6 = byteBuffer.getInt();
                if (isoGridSquare != null) {
                    for (int int7 = 0; int7 < isoGridSquare.getWorldObjects().size(); int7++) {
                        IsoWorldInventoryObject isoWorldInventoryObject = (IsoWorldInventoryObject)isoGridSquare.getWorldObjects().get(int7);
                        if (isoWorldInventoryObject.getItem() != null && isoWorldInventoryObject.getItem().id == int6) {
                            readItemStats(byteBuffer, isoWorldInventoryObject.getItem());
                            break;
                        }

                        if (isoWorldInventoryObject.getItem() instanceof InventoryContainer) {
                            ItemContainer itemContainer3 = ((InventoryContainer)isoWorldInventoryObject.getItem()).getInventory();
                            InventoryItem inventoryItem3 = itemContainer3.getItemWithID(int6);
                            if (inventoryItem3 != null) {
                                readItemStats(byteBuffer, inventoryItem3);
                                break;
                            }
                        }
                    }
                }
                break;
            case 2:
                byte byte1 = byteBuffer.get();
                byte byte2 = byteBuffer.get();
                int int4 = byteBuffer.getInt();
                if (isoGridSquare != null && byte1 >= 0 && byte1 < isoGridSquare.getObjects().size()) {
                    IsoObject isoObject = isoGridSquare.getObjects().get(byte1);
                    ItemContainer itemContainer1 = isoObject.getContainerByIndex(byte2);
                    if (itemContainer1 != null) {
                        InventoryItem inventoryItem1 = itemContainer1.getItemWithID(int4);
                        if (inventoryItem1 != null) {
                            readItemStats(byteBuffer, inventoryItem1);
                        }
                    }
                }
                break;
            case 3:
                short short1 = byteBuffer.getShort();
                byte byte0 = byteBuffer.get();
                int int3 = byteBuffer.getInt();
                BaseVehicle baseVehicle = VehicleManager.instance.getVehicleByID(short1);
                if (baseVehicle != null) {
                    VehiclePart vehiclePart = baseVehicle.getPartByIndex(byte0);
                    if (vehiclePart != null) {
                        ItemContainer itemContainer0 = vehiclePart.getItemContainer();
                        if (itemContainer0 != null) {
                            InventoryItem inventoryItem0 = itemContainer0.getItemWithID(int3);
                            if (inventoryItem0 != null) {
                                readItemStats(byteBuffer, inventoryItem0);
                            }
                        }
                    }
                }
        }

        for (int int8 = 0; int8 < udpEngine.connections.size(); int8++) {
            UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int8);
            if (udpConnection0 != udpConnection1 && udpConnection0.RelevantTo((float)int0, (float)int1)) {
                ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                PacketTypes.PacketType.ItemStats.doPacket(byteBufferWriter);
                byteBuffer.rewind();
                byteBufferWriter.bb.put(byteBuffer);
                PacketTypes.PacketType.ItemStats.send(udpConnection0);
            }
        }
    }

    static void receiveRequestItemsForContainer(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        ByteBufferReader byteBufferReader = new ByteBufferReader(byteBuffer);
        short short0 = byteBuffer.getShort();
        String string0 = zombie.GameWindow.ReadString(byteBuffer);
        String string1 = zombie.GameWindow.ReadString(byteBuffer);
        int int0 = byteBufferReader.getInt();
        int int1 = byteBufferReader.getInt();
        int int2 = byteBufferReader.getInt();
        short short1 = byteBufferReader.getShort();
        byte byte0 = -1;
        byte byte1 = -1;
        int int3 = 0;
        short short2 = 0;
        IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare(int0, int1, int2);
        IsoObject isoObject = null;
        ItemContainer itemContainer = null;
        if (short1 == 2) {
            byte0 = byteBufferReader.getByte();
            byte1 = byteBufferReader.getByte();
            if (isoGridSquare != null && byte0 >= 0 && byte0 < isoGridSquare.getObjects().size()) {
                isoObject = isoGridSquare.getObjects().get(byte0);
                if (isoObject != null) {
                    itemContainer = isoObject.getContainerByIndex(byte1);
                    if (itemContainer == null || itemContainer.isExplored()) {
                        return;
                    }
                }
            }
        } else if (short1 == 3) {
            short2 = byteBufferReader.getShort();
            byte1 = byteBufferReader.getByte();
            BaseVehicle baseVehicle = VehicleManager.instance.getVehicleByID(short2);
            if (baseVehicle != null) {
                VehiclePart vehiclePart = baseVehicle.getPartByIndex(byte1);
                itemContainer = vehiclePart == null ? null : vehiclePart.getItemContainer();
                if (itemContainer == null || itemContainer.isExplored()) {
                    return;
                }
            }
        } else if (short1 == 1) {
            int3 = byteBufferReader.getInt();

            for (int int4 = 0; int4 < isoGridSquare.getWorldObjects().size(); int4++) {
                IsoWorldInventoryObject isoWorldInventoryObject = (IsoWorldInventoryObject)isoGridSquare.getWorldObjects().get(int4);
                if (isoWorldInventoryObject != null
                    && isoWorldInventoryObject.getItem() instanceof InventoryContainer
                    && isoWorldInventoryObject.getItem().id == int3) {
                    itemContainer = ((InventoryContainer)isoWorldInventoryObject.getItem()).getInventory();
                    break;
                }
            }
        } else if (short1 == 0) {
            byte0 = byteBufferReader.getByte();
            if (isoGridSquare != null && byte0 >= 0 && byte0 < isoGridSquare.getStaticMovingObjects().size()) {
                isoObject = (IsoObject)isoGridSquare.getStaticMovingObjects().get(byte0);
                if (isoObject != null && isoObject.getContainer() != null) {
                    if (isoObject.getContainer().isExplored()) {
                        return;
                    }

                    itemContainer = isoObject.getContainer();
                }
            }
        }

        if (itemContainer != null && !itemContainer.isExplored()) {
            itemContainer.setExplored(true);
            int int5 = itemContainer.Items.size();
            ItemPickerJava.fillContainer(itemContainer, (IsoPlayer)IDToPlayerMap.get(short0));
            if (int5 != itemContainer.Items.size()) {
                for (int int6 = 0; int6 < udpEngine.connections.size(); int6++) {
                    UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(int6);
                    if (udpConnection.RelevantTo((float)isoGridSquare.x, (float)isoGridSquare.y)) {
                        ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                        PacketTypes.PacketType.AddInventoryItemToContainer.doPacket(byteBufferWriter);
                        byteBufferWriter.putShort(short1);
                        byteBufferWriter.putInt(int0);
                        byteBufferWriter.putInt(int1);
                        byteBufferWriter.putInt(int2);
                        if (short1 == 0) {
                            byteBufferWriter.putByte(byte0);
                        } else if (short1 == 1) {
                            byteBufferWriter.putInt(int3);
                        } else if (short1 == 3) {
                            byteBufferWriter.putShort(short2);
                            byteBufferWriter.putByte(byte1);
                        } else {
                            byteBufferWriter.putByte(byte0);
                            byteBufferWriter.putByte(byte1);
                        }

                        try {
                            CompressIdenticalItems.save(byteBufferWriter.bb, itemContainer.getItems(), null);
                        } catch (Exception exception) {
                            exception.printStackTrace();
                        }

                        PacketTypes.PacketType.AddInventoryItemToContainer.send(udpConnection);
                    }
                }
            }
        }
    }

    public static void sendItemsInContainer(IsoObject o, ItemContainer container) {
        if (udpEngine != null) {
            if (container == null) {
                DebugLog.log("sendItemsInContainer: container is null");
            } else {
                if (o instanceof IsoWorldInventoryObject isoWorldInventoryObject) {
                    if (!(isoWorldInventoryObject.getItem() instanceof InventoryContainer)) {
                        DebugLog.log("sendItemsInContainer: IsoWorldInventoryObject item isn't a container");
                        return;
                    }

                    InventoryContainer inventoryContainer = (InventoryContainer)isoWorldInventoryObject.getItem();
                    if (inventoryContainer.getInventory() != container) {
                        DebugLog.log("sendItemsInContainer: wrong container for IsoWorldInventoryObject");
                        return;
                    }
                } else if (o instanceof BaseVehicle) {
                    if (container.vehiclePart == null || container.vehiclePart.getItemContainer() != container || container.vehiclePart.getVehicle() != o) {
                        DebugLog.log("sendItemsInContainer: wrong container for BaseVehicle");
                        return;
                    }
                } else if (o instanceof IsoDeadBody) {
                    if (container != o.getContainer()) {
                        DebugLog.log("sendItemsInContainer: wrong container for IsoDeadBody");
                        return;
                    }
                } else if (o.getContainerIndex(container) == -1) {
                    DebugLog.log("sendItemsInContainer: wrong container for IsoObject");
                    return;
                }

                if (o != null && container != null && !container.getItems().isEmpty()) {
                    for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                        UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
                        if (udpConnection.RelevantTo((float)o.square.x, (float)o.square.y)) {
                            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                            PacketTypes.PacketType.AddInventoryItemToContainer.doPacket(byteBufferWriter);
                            if (o instanceof IsoDeadBody) {
                                byteBufferWriter.putShort((short)0);
                            } else if (o instanceof IsoWorldInventoryObject) {
                                byteBufferWriter.putShort((short)1);
                            } else if (o instanceof BaseVehicle) {
                                byteBufferWriter.putShort((short)3);
                            } else {
                                byteBufferWriter.putShort((short)2);
                            }

                            byteBufferWriter.putInt(o.getSquare().getX());
                            byteBufferWriter.putInt(o.getSquare().getY());
                            byteBufferWriter.putInt(o.getSquare().getZ());
                            if (o instanceof IsoDeadBody) {
                                byteBufferWriter.putByte((byte)o.getStaticMovingObjectIndex());
                            } else if (o instanceof IsoWorldInventoryObject) {
                                byteBufferWriter.putInt(((IsoWorldInventoryObject)o).getItem().id);
                            } else if (o instanceof BaseVehicle) {
                                byteBufferWriter.putShort(((BaseVehicle)o).VehicleID);
                                byteBufferWriter.putByte((byte)container.vehiclePart.getIndex());
                            } else {
                                byteBufferWriter.putByte((byte)o.getObjectIndex());
                                byteBufferWriter.putByte((byte)o.getContainerIndex(container));
                            }

                            try {
                                CompressIdenticalItems.save(byteBufferWriter.bb, container.getItems(), null);
                            } catch (Exception exception) {
                                exception.printStackTrace();
                            }

                            PacketTypes.PacketType.AddInventoryItemToContainer.send(udpConnection);
                        }
                    }
                }
            }
        }
    }

    private static void logDupeItem(UdpConnection udpConnection, String string1) {
        IsoPlayer isoPlayer = null;

        for (int _int = 0; _int < Players.size(); _int++) {
            if (udpConnection.username.equals(((IsoPlayer)Players.get(_int)).username)) {
                isoPlayer = (IsoPlayer)Players.get(_int);
                break;
            }
        }

        String string0 = "";
        if (isoPlayer != null) {
            string0 = LoggerManager.getPlayerCoords(isoPlayer);
            LoggerManager.getLogger("user").write("Error: Dupe item ID for " + isoPlayer.getDisplayName() + " " + string0);
        }

        ServerWorldDatabase.instance.addUserlog(udpConnection.username, Userlog.UserlogType.DupeItem, string1, GameServer.class.getSimpleName(), 1);
    }

    static void receiveAddInventoryItemToContainer(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        ByteBufferReader byteBufferReader = new ByteBufferReader(byteBuffer);
        short short0 = byteBufferReader.getShort();
        int int0 = byteBufferReader.getInt();
        int int1 = byteBufferReader.getInt();
        int int2 = byteBufferReader.getInt();
        IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare(int0, int1, int2);
        HashSet hashSet = new HashSet();
        byte byte0 = 0;
        if (isoGridSquare == null) {
            DebugLog.log("ERROR sendItemsToContainer square is null");
        } else {
            ItemContainer itemContainer = null;
            IsoObject isoObject0 = null;
            if (short0 == 0) {
                byte byte1 = byteBufferReader.getByte();
                if (byte1 < 0 || byte1 >= isoGridSquare.getStaticMovingObjects().size()) {
                    DebugLog.log("ERROR sendItemsToContainer invalid corpse index");
                    return;
                }

                IsoObject isoObject1 = (IsoObject)isoGridSquare.getStaticMovingObjects().get(byte1);
                if (isoObject1 != null && isoObject1.getContainer() != null) {
                    itemContainer = isoObject1.getContainer();
                }
            } else if (short0 == 1) {
                int int3 = byteBufferReader.getInt();

                for (int int4 = 0; int4 < isoGridSquare.getWorldObjects().size(); int4++) {
                    IsoWorldInventoryObject isoWorldInventoryObject = (IsoWorldInventoryObject)isoGridSquare.getWorldObjects().get(int4);
                    if (isoWorldInventoryObject != null
                        && isoWorldInventoryObject.getItem() instanceof InventoryContainer
                        && isoWorldInventoryObject.getItem().id == int3) {
                        itemContainer = ((InventoryContainer)isoWorldInventoryObject.getItem()).getInventory();
                        break;
                    }
                }

                if (itemContainer == null) {
                    DebugLog.log("ERROR sendItemsToContainer can't find world item with id=" + int3);
                    return;
                }
            } else if (short0 == 2) {
                byte byte2 = byteBufferReader.getByte();
                byte byte3 = byteBufferReader.getByte();
                if (byte2 < 0 || byte2 >= isoGridSquare.getObjects().size()) {
                    DebugLog.log("ERROR sendItemsToContainer invalid object index");

                    for (int int5 = 0; int5 < isoGridSquare.getObjects().size(); int5++) {
                        if (isoGridSquare.getObjects().get(int5).getContainer() != null) {
                            byte2 = (byte)int5;
                            byte3 = 0;
                            break;
                        }
                    }

                    if (byte2 == -1) {
                        return;
                    }
                }

                isoObject0 = isoGridSquare.getObjects().get(byte2);
                itemContainer = isoObject0 != null ? isoObject0.getContainerByIndex(byte3) : null;
            } else if (short0 == 3) {
                short short1 = byteBufferReader.getShort();
                byte byte4 = byteBufferReader.getByte();
                BaseVehicle baseVehicle = VehicleManager.instance.getVehicleByID(short1);
                if (baseVehicle == null) {
                    DebugLog.log("ERROR sendItemsToContainer invalid vehicle id");
                    return;
                }

                VehiclePart vehiclePart = baseVehicle.getPartByIndex(byte4);
                itemContainer = vehiclePart == null ? null : vehiclePart.getItemContainer();
            }

            if (itemContainer != null) {
                try {
                    ArrayList arrayList = CompressIdenticalItems.load(byteBufferReader.bb, 195, null, null);

                    for (int int6 = 0; int6 < arrayList.size(); int6++) {
                        InventoryItem inventoryItem = (InventoryItem)arrayList.get(int6);
                        if (inventoryItem != null) {
                            if (itemContainer.containsID(inventoryItem.id)) {
                                System.out.println("Error: Dupe item ID for " + udpConnection0.username);
                                logDupeItem(udpConnection0, inventoryItem.getDisplayName());
                            } else {
                                itemContainer.addItem(inventoryItem);
                                itemContainer.setExplored(true);
                                hashSet.add(inventoryItem.getFullType());
                                if (isoObject0 instanceof IsoMannequin) {
                                    ((IsoMannequin)isoObject0).wearItem(inventoryItem, null);
                                }
                            }
                        }
                    }
                } catch (Exception exception) {
                    exception.printStackTrace();
                }

                if (isoObject0 != null) {
                    LuaManager.updateOverlaySprite(isoObject0);
                    if ("campfire".equals(itemContainer.getType())) {
                        isoObject0.sendObjectChange("container.customTemperature");
                    }
                }
            }
        }

        for (int int7 = 0; int7 < udpEngine.connections.size(); int7++) {
            UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(int7);
            if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()
                && udpConnection1.RelevantTo((float)isoGridSquare.x, (float)isoGridSquare.y)) {
                byteBuffer.rewind();
                ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                PacketTypes.PacketType.AddInventoryItemToContainer.doPacket(byteBufferWriter);
                byteBufferWriter.bb.put(byteBuffer);
                PacketTypes.PacketType.AddInventoryItemToContainer.send(udpConnection1);
            }
        }

        LoggerManager.getLogger("item")
            .write(
                udpConnection0.idStr
                    + " \""
                    + udpConnection0.username
                    + "\" container +"
                    + byte0
                    + " "
                    + int0
                    + ","
                    + int1
                    + ","
                    + int2
                    + " "
                    + hashSet.toString()
            );
    }

    public static void addConnection(UdpConnection con) {
        synchronized (MainLoopNetDataHighPriorityQ) {
            MainLoopNetDataHighPriorityQ.add(new GameServer.DelayedConnection(con, true));
        }
    }

    public static void addDisconnect(UdpConnection con) {
        synchronized (MainLoopNetDataHighPriorityQ) {
            MainLoopNetDataHighPriorityQ.add(new GameServer.DelayedConnection(con, false));
        }
    }

    public static void disconnectPlayer(IsoPlayer player, UdpConnection connection) {
        if (player != null) {
            SafetySystemManager.storeSafety(player);
            ChatServer.getInstance().disconnectPlayer(player.getOnlineID());
            if (player.getVehicle() != null) {
                VehiclesDB2.instance.updateVehicleAndTrailer(player.getVehicle());
                if (player.getVehicle().isDriver(player) && player.getVehicle().isNetPlayerId(player.getOnlineID())) {
                    player.getVehicle().setNetPlayerAuthorization(BaseVehicle.Authorization.Server, -1);
                    player.getVehicle().getController().clientForce = 0.0F;
                    player.getVehicle().jniLinearVelocity.set(0.0F, 0.0F, 0.0F);
                }

                int int0 = player.getVehicle().getSeat(player);
                if (int0 != -1) {
                    player.getVehicle().clearPassenger(int0);
                }
            }

            if (!player.isDead()) {
                ServerWorldDatabase.instance.saveTransactionID(player.username, player.getTransactionID());
            }

            NetworkZombieManager.getInstance().clearTargetAuth(connection, player);
            player.removeFromWorld();
            player.removeFromSquare();
            PlayerToAddressMap.remove(player);
            IDToAddressMap.remove(player.OnlineID);
            IDToPlayerMap.remove(player.OnlineID);
            Players.remove(player);
            SafeHouse.updateSafehousePlayersConnected();
            SafeHouse safeHouse = SafeHouse.hasSafehouse(player);
            if (safeHouse != null && safeHouse.isOwner(player)) {
                for (IsoPlayer isoPlayer : IDToPlayerMap.values()) {
                    safeHouse.checkTrespass(isoPlayer);
                }
            }

            connection.usernames[player.PlayerIndex] = null;
            connection.players[player.PlayerIndex] = null;
            connection.playerIDs[player.PlayerIndex] = -1;
            connection.ReleventPos[player.PlayerIndex] = null;
            connection.connectArea[player.PlayerIndex] = null;

            for (int int1 = 0; int1 < udpEngine.connections.size(); int1++) {
                UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(int1);
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.PlayerTimeout.doPacket(byteBufferWriter);
                byteBufferWriter.putShort(player.OnlineID);
                PacketTypes.PacketType.PlayerTimeout.send(udpConnection);
            }

            ServerLOS.instance.removePlayer(player);
            ZombiePopulationManager.instance.updateLoadedAreas();
            DebugLog.log(DebugType.Network, "Disconnected player \"" + player.getDisplayName() + "\" " + connection.idStr);
            LoggerManager.getLogger("user")
                .write(connection.idStr + " \"" + player.getUsername() + "\" disconnected player " + LoggerManager.getPlayerCoords(player));
        }
    }

    public static void heartBeat() {
        count++;
    }

    public static short getFreeSlot() {
        for (short _short = 0; _short < udpEngine.getMaxConnections(); _short++) {
            if (SlotToConnection[_short] == null) {
                return _short;
            }
        }

        return -1;
    }

    public static void receiveClientConnect(UdpConnection connection, ServerWorldDatabase.LogonResult r) {
        ConnectionManager.log("receive-packet", "client-connect", connection);
        short short0 = getFreeSlot();
        short short1 = (short)(short0 * 4);
        if (connection.playerDownloadServer != null) {
            try {
                IDToAddressMap.put(short1, connection.getConnectedGUID());
                connection.playerDownloadServer.destroy();
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }

        playerToCoordsMap.put(short1, new Vector2());
        playerMovedToFastMap.put(short1, 0);
        SlotToConnection[short0] = connection;
        connection.playerIDs[0] = short1;
        IDToAddressMap.put(short1, connection.getConnectedGUID());
        connection.playerDownloadServer = new PlayerDownloadServer(connection);
        DebugLog.log(DebugType.Network, "Connected new client " + connection.username + " ID # " + short1);
        connection.playerDownloadServer.startConnectionTest();
        KahluaTable kahluaTable = SpawnPoints.instance.getSpawnRegions();

        for (int _int = 1; _int < kahluaTable.size() + 1; _int++) {
            ByteBufferWriter byteBufferWriter = connection.startPacket();
            PacketTypes.PacketType.SpawnRegion.doPacket(byteBufferWriter);
            byteBufferWriter.putInt(_int);

            try {
                ((KahluaTable)kahluaTable.rawget(_int)).save(byteBufferWriter.bb);
                PacketTypes.PacketType.SpawnRegion.send(connection);
            } catch (IOException iOException) {
                iOException.printStackTrace();
            }
        }

        RequestDataPacket requestDataPacket = new RequestDataPacket();
        requestDataPacket.sendConnectingDetails(connection, r);
    }

    static void receiveReplaceOnCooked(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        ByteBufferReader byteBufferReader = new ByteBufferReader(byteBuffer);
        int int0 = byteBufferReader.getInt();
        int int1 = byteBufferReader.getInt();
        int int2 = byteBufferReader.getInt();
        byte byte0 = byteBufferReader.getByte();
        byte byte1 = byteBufferReader.getByte();
        int int3 = byteBufferReader.getInt();
        IsoGridSquare isoGridSquare = ServerMap.instance.getGridSquare(int0, int1, int2);
        if (isoGridSquare != null) {
            if (byte0 >= 0 && byte0 < isoGridSquare.getObjects().size()) {
                IsoObject isoObject = isoGridSquare.getObjects().get(byte0);
                if (isoObject != null) {
                    ItemContainer itemContainer = isoObject.getContainerByIndex(byte1);
                    if (itemContainer != null) {
                        InventoryItem inventoryItem0 = itemContainer.getItemWithID(int3);
                        if (inventoryItem0 != null) {
                            Food food = Type.tryCastTo(inventoryItem0, Food.class);
                            if (food != null) {
                                if (food.getReplaceOnCooked() != null && !food.isRotten()) {
                                    for (int int4 = 0; int4 < food.getReplaceOnCooked().size(); int4++) {
                                        InventoryItem inventoryItem1 = itemContainer.AddItem((String)food.getReplaceOnCooked().get(int4));
                                        if (inventoryItem1 != null) {
                                            inventoryItem1.copyConditionModData(food);
                                            if (inventoryItem1 instanceof Food && food instanceof Food) {
                                            }

                                            if (inventoryItem1 instanceof Food && ((Food)inventoryItem1).isBadInMicrowave() && itemContainer.isMicrowave()) {
                                                inventoryItem1.setUnhappyChange(5.0F);
                                                inventoryItem1.setBoredomChange(5.0F);
                                                ((Food)inventoryItem1).setCookedInMicrowave(true);
                                            }

                                            sendAddItemToContainer(itemContainer, inventoryItem1);
                                        }
                                    }

                                    sendRemoveItemFromContainer(itemContainer, food);
                                    itemContainer.Remove(food);
                                    IsoWorld.instance.CurrentCell.addToProcessItemsRemove(food);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    static void receivePlayerDataRequest(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        PlayerDataRequestPacket playerDataRequestPacket = new PlayerDataRequestPacket();
        playerDataRequestPacket.parse(byteBuffer, udpConnection);
        if (playerDataRequestPacket.isConsistent()) {
            playerDataRequestPacket.process(udpConnection);
        }
    }

    static void receiveRequestData(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        RequestDataPacket requestDataPacket = new RequestDataPacket();
        requestDataPacket.parse(byteBuffer, udpConnection);
        requestDataPacket.processServer(PacketTypes.PacketType.RequestData, udpConnection);
    }

    public static void sendMetaGrid(int cellX, int cellY, int roomID, UdpConnection connection) {
        IsoMetaGrid isoMetaGrid = IsoWorld.instance.MetaGrid;
        if (cellX >= isoMetaGrid.getMinX() && cellX <= isoMetaGrid.getMaxX() && cellY >= isoMetaGrid.getMinY() && cellY <= isoMetaGrid.getMaxY()) {
            IsoMetaCell isoMetaCell = isoMetaGrid.getCellData(cellX, cellY);
            if (isoMetaCell.info != null && roomID >= 0 && roomID < isoMetaCell.info.RoomList.size()) {
                ByteBufferWriter byteBufferWriter = connection.startPacket();
                PacketTypes.PacketType.MetaGrid.doPacket(byteBufferWriter);
                byteBufferWriter.putShort((short)cellX);
                byteBufferWriter.putShort((short)cellY);
                byteBufferWriter.putShort((short)roomID);
                byteBufferWriter.putBoolean(isoMetaCell.info.getRoom(roomID).def.bLightsActive);
                PacketTypes.PacketType.MetaGrid.send(connection);
            }
        }
    }

    public static void sendMetaGrid(int cellX, int cellY, int roomID) {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            sendMetaGrid(cellX, cellY, roomID, udpConnection);
        }
    }

    private static void preventIndoorZombies(int int0, int int1, int int2) {
        RoomDef roomDef = IsoWorld.instance.MetaGrid.getRoomAt(int0, int1, int2);
        if (roomDef != null) {
            boolean _boolean = isSpawnBuilding(roomDef.getBuilding());
            roomDef.getBuilding().setAllExplored(true);
            roomDef.getBuilding().setAlarmed(false);
            ArrayList arrayList = IsoWorld.instance.CurrentCell.getZombieList();

            for (int int3 = 0; int3 < arrayList.size(); int3++) {
                IsoZombie isoZombie = (IsoZombie)arrayList.get(int3);
                if ((_boolean || isoZombie.bIndoorZombie)
                    && isoZombie.getSquare() != null
                    && isoZombie.getSquare().getRoom() != null
                    && isoZombie.getSquare().getRoom().def.building == roomDef.getBuilding()) {
                    zombie.VirtualZombieManager.instance.removeZombieFromWorld(isoZombie);
                    if (int3 >= arrayList.size() || arrayList.get(int3) != isoZombie) {
                        int3--;
                    }
                }
            }
        }
    }

    private static void receivePlayerConnect(ByteBuffer byteBuffer, UdpConnection udpConnection0, String string0) {
        ConnectionManager.log("receive-packet", "player-connect", udpConnection0);
        DebugLog.General.println("User:'" + string0 + "' ip:" + udpConnection0.ip + " is trying to connect");
        byte byte0 = byteBuffer.get();
        if (byte0 >= 0 && byte0 < 4 && udpConnection0.players[byte0] == null) {
            byte byte1 = (byte)Math.min(20, byteBuffer.get());
            udpConnection0.ReleventRange = (byte)(byte1 / 2 + 2);
            float float0 = byteBuffer.getFloat();
            float float1 = byteBuffer.getFloat();
            float float2 = byteBuffer.getFloat();
            udpConnection0.ReleventPos[byte0].x = float0;
            udpConnection0.ReleventPos[byte0].y = float1;
            udpConnection0.ReleventPos[byte0].z = float2;
            udpConnection0.connectArea[byte0] = null;
            udpConnection0.ChunkGridWidth = byte1;
            udpConnection0.loadedCells[byte0] = new ClientServerMap(byte0, (int)float0, (int)float1, byte1);
            SurvivorDesc survivorDesc = SurvivorFactory.CreateSurvivor();

            try {
                survivorDesc.load(byteBuffer, 195, null);
            } catch (IOException iOException0) {
                iOException0.printStackTrace();
            }

            IsoPlayer isoPlayer0 = new IsoPlayer(null, survivorDesc, (int)float0, (int)float1, (int)float2);
            isoPlayer0.realx = float0;
            isoPlayer0.realy = float1;
            isoPlayer0.realz = (byte)((int)float2);
            isoPlayer0.PlayerIndex = byte0;
            isoPlayer0.OnlineChunkGridWidth = byte1;
            Players.add(isoPlayer0);
            isoPlayer0.bRemote = true;

            try {
                isoPlayer0.getHumanVisual().load(byteBuffer, 195);
                isoPlayer0.getItemVisuals().load(byteBuffer, 195);
            } catch (IOException iOException1) {
                iOException1.printStackTrace();
            }

            short _short = udpConnection0.playerIDs[byte0];
            IDToPlayerMap.put(_short, isoPlayer0);
            udpConnection0.players[byte0] = isoPlayer0;
            PlayerToAddressMap.put(isoPlayer0, udpConnection0.getConnectedGUID());
            isoPlayer0.setOnlineID(_short);

            try {
                isoPlayer0.getXp().load(byteBuffer, 195);
            } catch (IOException iOException2) {
                iOException2.printStackTrace();
            }

            isoPlayer0.setAllChatMuted(byteBuffer.get() == 1);
            udpConnection0.allChatMuted = isoPlayer0.isAllChatMuted();
            isoPlayer0.setTagPrefix(zombie.GameWindow.ReadString(byteBuffer));
            isoPlayer0.setTagColor(new ColorInfo(byteBuffer.getFloat(), byteBuffer.getFloat(), byteBuffer.getFloat(), 1.0F));
            isoPlayer0.setTransactionID(byteBuffer.getInt());
            isoPlayer0.setHoursSurvived(byteBuffer.getDouble());
            isoPlayer0.setZombieKills(byteBuffer.getInt());
            isoPlayer0.setDisplayName(zombie.GameWindow.ReadString(byteBuffer));
            isoPlayer0.setSpeakColour(new Color(byteBuffer.getFloat(), byteBuffer.getFloat(), byteBuffer.getFloat(), 1.0F));
            isoPlayer0.showTag = byteBuffer.get() == 1;
            isoPlayer0.factionPvp = byteBuffer.get() == 1;
            if (SteamUtils.isSteamModeEnabled()) {
                isoPlayer0.setSteamID(udpConnection0.steamID);
                String string1 = zombie.GameWindow.ReadStringUTF(byteBuffer);
                SteamGameServer.BUpdateUserData(udpConnection0.steamID, udpConnection0.username, 0);
            }

            byte byte2 = byteBuffer.get();
            Object object = null;
            if (byte2 == 1) {
                try {
                    object = InventoryItem.loadItem(byteBuffer, 195);
                } catch (IOException iOException3) {
                    iOException3.printStackTrace();
                    return;
                }

                if (object == null) {
                    LoggerManager.getLogger("user").write(udpConnection0.idStr + " equipped unknown item");
                    return;
                }

                isoPlayer0.setPrimaryHandItem((InventoryItem)object);
            }

            object = null;
            byte byte3 = byteBuffer.get();
            if (byte3 == 2) {
                isoPlayer0.setSecondaryHandItem(isoPlayer0.getPrimaryHandItem());
            }

            if (byte3 == 1) {
                try {
                    object = InventoryItem.loadItem(byteBuffer, 195);
                } catch (IOException iOException4) {
                    iOException4.printStackTrace();
                    return;
                }

                if (object == null) {
                    LoggerManager.getLogger("user").write(udpConnection0.idStr + " equipped unknown item");
                    return;
                }

                isoPlayer0.setSecondaryHandItem((InventoryItem)object);
            }

            int int0 = byteBuffer.getInt();

            for (int int1 = 0; int1 < int0; int1++) {
                String string2 = zombie.GameWindow.ReadString(byteBuffer);
                InventoryItem inventoryItem = InventoryItemFactory.CreateItem(zombie.GameWindow.ReadString(byteBuffer));
                if (inventoryItem != null) {
                    isoPlayer0.setAttachedItem(string2, inventoryItem);
                }
            }

            int int2 = byteBuffer.getInt();
            isoPlayer0.remoteSneakLvl = int2;
            isoPlayer0.username = string0;
            isoPlayer0.accessLevel = PlayerType.toString(udpConnection0.accessLevel);
            if (!isoPlayer0.accessLevel.equals("") && CoopSlave.instance == null) {
                isoPlayer0.setGhostMode(true);
                isoPlayer0.setInvisible(true);
                isoPlayer0.setGodMod(true);
            }

            ChatServer.getInstance().initPlayer(isoPlayer0.OnlineID);
            udpConnection0.setFullyConnected();
            sendWeather(udpConnection0);
            SafetySystemManager.restoreSafety(isoPlayer0);

            for (int int3 = 0; int3 < udpEngine.connections.size(); int3++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(int3);
                sendPlayerConnect(isoPlayer0, udpConnection1);
            }

            SyncInjuriesPacket syncInjuriesPacket = new SyncInjuriesPacket();

            for (IsoPlayer isoPlayer1 : IDToPlayerMap.values()) {
                if (isoPlayer1.getOnlineID() != isoPlayer0.getOnlineID() && isoPlayer1.isAlive()) {
                    sendPlayerConnect(isoPlayer1, udpConnection0);
                    syncInjuriesPacket.set(isoPlayer1);
                    sendPlayerInjuries(udpConnection0, syncInjuriesPacket);
                }
            }

            udpConnection0.loadedCells[byte0].setLoaded();
            udpConnection0.loadedCells[byte0].sendPacket(udpConnection0);
            preventIndoorZombies((int)float0, (int)float1, (int)float2);
            ServerLOS.instance.addPlayer(isoPlayer0);
            LoggerManager.getLogger("user")
                .write(udpConnection0.idStr + " \"" + isoPlayer0.username + "\" fully connected " + LoggerManager.getPlayerCoords(isoPlayer0));

            try {
                for (NonPvpZone nonPvpZone : NonPvpZone.getAllZones()) {
                    sendNonPvpZone(nonPvpZone, false, udpConnection0);
                }
            } catch (Exception exception) {
                DebugLog.Multiplayer.printException(exception, "Send non PVP zones", LogSeverity.Error);
            }
        }
    }

    static void receivePlayerSave(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        if ((Calendar.getInstance().getTimeInMillis() - previousSave) / 60000L >= 0L) {
            byte _byte = byteBuffer.get();
            if (_byte >= 0 && _byte < 4) {
                short _short = byteBuffer.getShort();
                float float0 = byteBuffer.getFloat();
                float float1 = byteBuffer.getFloat();
                float float2 = byteBuffer.getFloat();
                ServerMap.instance.saveZoneInsidePlayerInfluence(_short);
            }
        }
    }

    static void receiveSendPlayerProfile(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        ServerPlayerDB.getInstance().serverUpdateNetworkCharacter(byteBuffer, udpConnection);
    }

    static void receiveLoadPlayerProfile(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        ServerPlayerDB.getInstance().serverLoadNetworkCharacter(byteBuffer, udpConnection);
    }

    private static void coopAccessGranted(int _int, UdpConnection udpConnection) {
        ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
        PacketTypes.PacketType.AddCoopPlayer.doPacket(byteBufferWriter);
        byteBufferWriter.putBoolean(true);
        byteBufferWriter.putByte((byte)_int);
        PacketTypes.PacketType.AddCoopPlayer.send(udpConnection);
    }

    private static void coopAccessDenied(String string, int _int, UdpConnection udpConnection) {
        ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
        PacketTypes.PacketType.AddCoopPlayer.doPacket(byteBufferWriter);
        byteBufferWriter.putBoolean(false);
        byteBufferWriter.putByte((byte)_int);
        byteBufferWriter.putUTF(string);
        PacketTypes.PacketType.AddCoopPlayer.send(udpConnection);
    }

    static void receiveAddCoopPlayer(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        byte byte0 = byteBuffer.get();
        byte byte1 = byteBuffer.get();
        if (!ServerOptions.instance.AllowCoop.getValue() && byte1 != 0) {
            coopAccessDenied("Coop players not allowed", byte1, udpConnection0);
        } else if (byte1 >= 0 && byte1 < 4) {
            if (udpConnection0.players[byte1] != null && !udpConnection0.players[byte1].isDead()) {
                coopAccessDenied("Coop player " + (byte1 + 1) + "/4 already exists", byte1, udpConnection0);
            } else if (byte0 != 1) {
                if (byte0 == 2) {
                    String string0 = udpConnection0.usernames[byte1];
                    if (string0 == null) {
                        coopAccessDenied("Coop player login wasn't received", byte1, udpConnection0);
                    } else {
                        DebugLog.log("coop player=" + (byte1 + 1) + "/4 username=\"" + string0 + "\" player info received");
                        receivePlayerConnect(byteBuffer, udpConnection0, string0);
                    }
                }
            } else {
                String string1 = zombie.GameWindow.ReadStringUTF(byteBuffer);
                if (string1.isEmpty()) {
                    coopAccessDenied("No username given", byte1, udpConnection0);
                } else {
                    for (int int0 = 0; int0 < udpEngine.connections.size(); int0++) {
                        UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(int0);

                        for (int int1 = 0; int1 < 4; int1++) {
                            if ((udpConnection1 != udpConnection0 || byte1 != int1) && string1.equals(udpConnection1.usernames[int1])) {
                                coopAccessDenied("User \"" + string1 + "\" already connected", byte1, udpConnection0);
                                return;
                            }
                        }
                    }

                    DebugLog.log("coop player=" + (byte1 + 1) + "/4 username=\"" + string1 + "\" is joining");
                    if (udpConnection0.players[byte1] != null) {
                        DebugLog.log("coop player=" + (byte1 + 1) + "/4 username=\"" + string1 + "\" is replacing dead player");
                        short short0 = udpConnection0.players[byte1].OnlineID;
                        disconnectPlayer(udpConnection0.players[byte1], udpConnection0);
                        float float0 = byteBuffer.getFloat();
                        float float1 = byteBuffer.getFloat();
                        udpConnection0.usernames[byte1] = string1;
                        udpConnection0.ReleventPos[byte1] = new Vector3(float0, float1, 0.0F);
                        udpConnection0.connectArea[byte1] = new Vector3(float0 / 10.0F, float1 / 10.0F, (float)udpConnection0.ChunkGridWidth);
                        udpConnection0.playerIDs[byte1] = short0;
                        IDToAddressMap.put(short0, udpConnection0.getConnectedGUID());
                        coopAccessGranted(byte1, udpConnection0);
                        ZombiePopulationManager.instance.updateLoadedAreas();
                        if (ChatServer.isInited()) {
                            ChatServer.getInstance().initPlayer(short0);
                        }
                    } else if (getPlayerCount() >= ServerOptions.getInstance().getMaxPlayers()) {
                        coopAccessDenied("Server is full", byte1, udpConnection0);
                    } else {
                        short short1 = -1;

                        for (short short2 = 0; short2 < udpEngine.getMaxConnections(); short2++) {
                            if (SlotToConnection[short2] == udpConnection0) {
                                short1 = short2;
                                break;
                            }
                        }

                        short short3 = (short)(short1 * 4 + byte1);
                        DebugLog.log("coop player=" + (byte1 + 1) + "/4 username=\"" + string1 + "\" assigned id=" + short3);
                        float float2 = byteBuffer.getFloat();
                        float float3 = byteBuffer.getFloat();
                        udpConnection0.usernames[byte1] = string1;
                        udpConnection0.ReleventPos[byte1] = new Vector3(float2, float3, 0.0F);
                        udpConnection0.playerIDs[byte1] = short3;
                        udpConnection0.connectArea[byte1] = new Vector3(float2 / 10.0F, float3 / 10.0F, (float)udpConnection0.ChunkGridWidth);
                        IDToAddressMap.put(short3, udpConnection0.getConnectedGUID());
                        coopAccessGranted(byte1, udpConnection0);
                        ZombiePopulationManager.instance.updateLoadedAreas();
                    }
                }
            }
        } else {
            coopAccessDenied("Invalid coop player index", byte1, udpConnection0);
        }
    }

    private static void sendInitialWorldState(UdpConnection udpConnection) {
        if (RainManager.isRaining()) {
            sendStartRain(udpConnection);
        }

        VehicleManager.instance.serverSendInitialWorldState(udpConnection);

        try {
            if (!ClimateManager.getInstance().isUpdated()) {
                ClimateManager.getInstance().update();
            }

            ClimateManager.getInstance().sendInitialState(udpConnection);
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    static void receiveObjectModData(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        int int3 = byteBuffer.getInt();
        boolean _boolean = byteBuffer.get() == 1;
        IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare(int0, int1, int2);
        if (isoGridSquare != null && int3 >= 0 && int3 < isoGridSquare.getObjects().size()) {
            IsoObject isoObject = isoGridSquare.getObjects().get(int3);
            if (_boolean) {
                int int4 = isoObject.getWaterAmount();

                try {
                    isoObject.getModData().load(byteBuffer, 195);
                } catch (IOException iOException) {
                    iOException.printStackTrace();
                }

                if (int4 != isoObject.getWaterAmount()) {
                    LuaEventManager.triggerEvent("OnWaterAmountChange", isoObject, int4);
                }
            } else if (isoObject.hasModData()) {
                isoObject.getModData().wipe();
            }

            for (int int5 = 0; int5 < udpEngine.connections.size(); int5++) {
                UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int5);
                if (udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID() && udpConnection0.RelevantTo((float)int0, (float)int1)) {
                    sendObjectModData(isoObject, udpConnection0);
                }
            }
        } else if (isoGridSquare != null) {
            DebugLog.log("receiveObjectModData: index=" + int3 + " is invalid x,y,z=" + int0 + "," + int1 + "," + int2);
        } else if (bDebug) {
            DebugLog.log("receiveObjectModData: sq is null x,y,z=" + int0 + "," + int1 + "," + int2);
        }
    }

    private static void sendObjectModData(IsoObject isoObject, UdpConnection udpConnection) {
        if (isoObject.getSquare() != null) {
            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
            PacketTypes.PacketType.ObjectModData.doPacket(byteBufferWriter);
            byteBufferWriter.putInt(isoObject.getSquare().getX());
            byteBufferWriter.putInt(isoObject.getSquare().getY());
            byteBufferWriter.putInt(isoObject.getSquare().getZ());
            byteBufferWriter.putInt(isoObject.getSquare().getObjects().indexOf(isoObject));
            if (isoObject.getModData().isEmpty()) {
                byteBufferWriter.putByte((byte)0);
            } else {
                byteBufferWriter.putByte((byte)1);

                try {
                    isoObject.getModData().save(byteBufferWriter.bb);
                } catch (IOException iOException) {
                    iOException.printStackTrace();
                }
            }

            PacketTypes.PacketType.ObjectModData.send(udpConnection);
        }
    }

    public static void sendObjectModData(IsoObject o) {
        if (!bSoftReset && !bFastForward) {
            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection.RelevantTo(o.getX(), o.getY())) {
                    sendObjectModData(o, udpConnection);
                }
            }
        }
    }

    public static void sendSlowFactor(IsoGameCharacter chr) {
        if (chr instanceof IsoPlayer) {
            if (PlayerToAddressMap.containsKey(chr)) {
                long _long = (Long)PlayerToAddressMap.get((IsoPlayer)chr);
                UdpConnection udpConnection = udpEngine.getActiveConnection(_long);
                if (udpConnection != null) {
                    ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                    PacketTypes.PacketType.SlowFactor.doPacket(byteBufferWriter);
                    byteBufferWriter.putByte((byte)((IsoPlayer)chr).PlayerIndex);
                    byteBufferWriter.putFloat(chr.getSlowTimer());
                    byteBufferWriter.putFloat(chr.getSlowFactor());
                    PacketTypes.PacketType.SlowFactor.send(udpConnection);
                }
            }
        }
    }

    private static void sendObjectChange(IsoObject isoObject, String string, KahluaTable kahluaTable, UdpConnection udpConnection) {
        if (isoObject.getSquare() != null) {
            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
            PacketTypes.PacketType.ObjectChange.doPacket(byteBufferWriter);
            if (isoObject instanceof IsoPlayer) {
                byteBufferWriter.putByte((byte)1);
                byteBufferWriter.putShort(((IsoPlayer)isoObject).OnlineID);
            } else if (isoObject instanceof BaseVehicle) {
                byteBufferWriter.putByte((byte)2);
                byteBufferWriter.putShort(((BaseVehicle)isoObject).getId());
            } else if (isoObject instanceof IsoWorldInventoryObject) {
                byteBufferWriter.putByte((byte)3);
                byteBufferWriter.putInt(isoObject.getSquare().getX());
                byteBufferWriter.putInt(isoObject.getSquare().getY());
                byteBufferWriter.putInt(isoObject.getSquare().getZ());
                byteBufferWriter.putInt(((IsoWorldInventoryObject)isoObject).getItem().getID());
            } else if (isoObject instanceof IsoDeadBody) {
                byteBufferWriter.putByte((byte)4);
                byteBufferWriter.putInt(isoObject.getSquare().getX());
                byteBufferWriter.putInt(isoObject.getSquare().getY());
                byteBufferWriter.putInt(isoObject.getSquare().getZ());
                byteBufferWriter.putInt(isoObject.getStaticMovingObjectIndex());
            } else {
                byteBufferWriter.putByte((byte)0);
                byteBufferWriter.putInt(isoObject.getSquare().getX());
                byteBufferWriter.putInt(isoObject.getSquare().getY());
                byteBufferWriter.putInt(isoObject.getSquare().getZ());
                byteBufferWriter.putInt(isoObject.getSquare().getObjects().indexOf(isoObject));
            }

            byteBufferWriter.putUTF(string);
            isoObject.saveChange(string, kahluaTable, byteBufferWriter.bb);
            PacketTypes.PacketType.ObjectChange.send(udpConnection);
        }
    }

    public static void sendObjectChange(IsoObject isoObject, String string, KahluaTable kahluaTable) {
        if (!bSoftReset) {
            if (isoObject != null) {
                for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                    UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
                    if (udpConnection.RelevantTo(isoObject.getX(), isoObject.getY())) {
                        sendObjectChange(isoObject, string, kahluaTable, udpConnection);
                    }
                }
            }
        }
    }

    public static void sendObjectChange(IsoObject isoObject, String string, Object... object0) {
        if (!bSoftReset) {
            if (object0.length == 0) {
                sendObjectChange(isoObject, string, (KahluaTable)null);
            } else if (object0.length % 2 == 0) {
                KahluaTable kahluaTable = LuaManager.platform.newTable();

                for (byte _byte = 0; _byte < object0.length; _byte += 2) {
                    Object object1 = object0[_byte + 1];
                    if (object1 instanceof Float) {
                        kahluaTable.rawset(object0[_byte], ((Float)object1).doubleValue());
                    } else if (object1 instanceof Integer) {
                        kahluaTable.rawset(object0[_byte], ((Integer)object1).doubleValue());
                    } else if (object1 instanceof Short) {
                        kahluaTable.rawset(object0[_byte], ((Short)object1).doubleValue());
                    } else {
                        kahluaTable.rawset(object0[_byte], object1);
                    }
                }

                sendObjectChange(isoObject, string, kahluaTable);
            }
        }
    }

    private static void updateHandEquips(UdpConnection udpConnection, IsoPlayer isoPlayer) {
        ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
        PacketTypes.PacketType.Equip.doPacket(byteBufferWriter);
        byteBufferWriter.putShort(isoPlayer.OnlineID);
        byteBufferWriter.putByte((byte)0);
        byteBufferWriter.putByte((byte)(isoPlayer.getPrimaryHandItem() != null ? 1 : 0));
        if (isoPlayer.getPrimaryHandItem() != null) {
            try {
                isoPlayer.getPrimaryHandItem().saveWithSize(byteBufferWriter.bb, false);
                if (isoPlayer.getPrimaryHandItem().getVisual() != null) {
                    byteBufferWriter.bb.put((byte)1);
                    isoPlayer.getPrimaryHandItem().getVisual().save(byteBufferWriter.bb);
                } else {
                    byteBufferWriter.bb.put((byte)0);
                }
            } catch (IOException iOException0) {
                iOException0.printStackTrace();
            }
        }

        PacketTypes.PacketType.Equip.send(udpConnection);
        byteBufferWriter = udpConnection.startPacket();
        PacketTypes.PacketType.Equip.doPacket(byteBufferWriter);
        byteBufferWriter.putShort(isoPlayer.OnlineID);
        byteBufferWriter.putByte((byte)1);
        if (isoPlayer.getSecondaryHandItem() == isoPlayer.getPrimaryHandItem() && isoPlayer.getSecondaryHandItem() != null) {
            byteBufferWriter.putByte((byte)2);
        } else {
            byteBufferWriter.putByte((byte)(isoPlayer.getSecondaryHandItem() != null ? 1 : 0));
        }

        if (isoPlayer.getSecondaryHandItem() != null) {
            try {
                isoPlayer.getSecondaryHandItem().saveWithSize(byteBufferWriter.bb, false);
                if (isoPlayer.getSecondaryHandItem().getVisual() != null) {
                    byteBufferWriter.bb.put((byte)1);
                    isoPlayer.getSecondaryHandItem().getVisual().save(byteBufferWriter.bb);
                } else {
                    byteBufferWriter.bb.put((byte)0);
                }
            } catch (IOException iOException1) {
                iOException1.printStackTrace();
            }
        }

        PacketTypes.PacketType.Equip.send(udpConnection);
    }

    public static void receiveSyncCustomLightSettings(ByteBuffer bb, UdpConnection connection, short packetType) {
        int int0 = bb.getInt();
        int int1 = bb.getInt();
        int int2 = bb.getInt();
        byte _byte = bb.get();
        IsoGridSquare isoGridSquare = ServerMap.instance.getGridSquare(int0, int1, int2);
        if (isoGridSquare != null && _byte >= 0 && _byte < isoGridSquare.getObjects().size()) {
            if (isoGridSquare.getObjects().get(_byte) instanceof IsoLightSwitch) {
                ((IsoLightSwitch)isoGridSquare.getObjects().get(_byte)).receiveSyncCustomizedSettings(bb, connection);
            } else {
                DebugLog.log("Sync Lightswitch custom settings: found object not a instance of IsoLightSwitch, x,y,z=" + int0 + "," + int1 + "," + int2);
            }
        } else if (isoGridSquare != null) {
            DebugLog.log("Sync Lightswitch custom settings: index=" + _byte + " is invalid x,y,z=" + int0 + "," + int1 + "," + int2);
        } else {
            DebugLog.log("Sync Lightswitch custom settings: sq is null x,y,z=" + int0 + "," + int1 + "," + int2);
        }
    }

    private static void sendAlarmClock_Player(short _short, int int0, boolean boolean0, int int1, int int2, boolean boolean1, UdpConnection udpConnection) {
        ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
        PacketTypes.PacketType.SyncAlarmClock.doPacket(byteBufferWriter);
        byteBufferWriter.putShort(AlarmClock.PacketPlayer);
        byteBufferWriter.putShort(_short);
        byteBufferWriter.putInt(int0);
        byteBufferWriter.putByte((byte)(boolean0 ? 1 : 0));
        if (!boolean0) {
            byteBufferWriter.putInt(int1);
            byteBufferWriter.putInt(int2);
            byteBufferWriter.putByte((byte)(boolean1 ? 1 : 0));
        }

        PacketTypes.PacketType.SyncAlarmClock.send(udpConnection);
    }

    private static void sendAlarmClock_World(
        int int0, int int1, int int2, int int3, boolean boolean0, int int4, int int5, boolean boolean1, UdpConnection udpConnection
    ) {
        ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
        PacketTypes.PacketType.SyncAlarmClock.doPacket(byteBufferWriter);
        byteBufferWriter.putShort(AlarmClock.PacketWorld);
        byteBufferWriter.putInt(int0);
        byteBufferWriter.putInt(int1);
        byteBufferWriter.putInt(int2);
        byteBufferWriter.putInt(int3);
        byteBufferWriter.putByte((byte)(boolean0 ? 1 : 0));
        if (!boolean0) {
            byteBufferWriter.putInt(int4);
            byteBufferWriter.putInt(int5);
            byteBufferWriter.putByte((byte)(boolean1 ? 1 : 0));
        }

        PacketTypes.PacketType.SyncAlarmClock.send(udpConnection);
    }

    static void receiveSyncAlarmClock(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        short short0 = byteBuffer.getShort();
        if (short0 == AlarmClock.PacketPlayer) {
            short short1 = byteBuffer.getShort();
            int int0 = byteBuffer.getInt();
            boolean boolean0 = byteBuffer.get() == 1;
            int int1 = 0;
            int int2 = 0;
            boolean boolean1 = false;
            if (!boolean0) {
                int1 = byteBuffer.getInt();
                int2 = byteBuffer.getInt();
                boolean1 = byteBuffer.get() == 1;
            }

            IsoPlayer isoPlayer = getPlayerFromConnection(udpConnection0, short1);
            if (isoPlayer != null) {
                for (int int3 = 0; int3 < udpEngine.connections.size(); int3++) {
                    UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(int3);
                    if (udpConnection1 != udpConnection0) {
                        sendAlarmClock_Player(isoPlayer.getOnlineID(), int0, boolean0, int1, int2, boolean1, udpConnection1);
                    }
                }
            }
        } else if (short0 == AlarmClock.PacketWorld) {
            int int4 = byteBuffer.getInt();
            int int5 = byteBuffer.getInt();
            int int6 = byteBuffer.getInt();
            int int7 = byteBuffer.getInt();
            boolean boolean2 = byteBuffer.get() == 1;
            int int8 = 0;
            int int9 = 0;
            boolean boolean3 = false;
            if (!boolean2) {
                int8 = byteBuffer.getInt();
                int9 = byteBuffer.getInt();
                boolean3 = byteBuffer.get() == 1;
            }

            IsoGridSquare isoGridSquare = ServerMap.instance.getGridSquare(int4, int5, int6);
            if (isoGridSquare == null) {
                DebugLog.log("SyncAlarmClock: sq is null x,y,z=" + int4 + "," + int5 + "," + int6);
            } else {
                AlarmClock alarmClock = null;

                for (int int10 = 0; int10 < isoGridSquare.getWorldObjects().size(); int10++) {
                    IsoWorldInventoryObject isoWorldInventoryObject = (IsoWorldInventoryObject)isoGridSquare.getWorldObjects().get(int10);
                    if (isoWorldInventoryObject != null
                        && isoWorldInventoryObject.getItem() instanceof AlarmClock
                        && isoWorldInventoryObject.getItem().id == int7) {
                        alarmClock = (AlarmClock)isoWorldInventoryObject.getItem();
                        break;
                    }
                }

                if (alarmClock == null) {
                    DebugLog.log("SyncAlarmClock: AlarmClock is null x,y,z=" + int4 + "," + int5 + "," + int6);
                } else {
                    if (boolean2) {
                        alarmClock.stopRinging();
                    } else {
                        alarmClock.setHour(int8);
                        alarmClock.setMinute(int9);
                        alarmClock.setAlarmSet(boolean3);
                    }

                    for (int int11 = 0; int11 < udpEngine.connections.size(); int11++) {
                        UdpConnection udpConnection2 = (UdpConnection)udpEngine.connections.get(int11);
                        if (udpConnection2 != udpConnection0) {
                            sendAlarmClock_World(int4, int5, int6, int7, boolean2, int8, int9, boolean3, udpConnection2);
                        }
                    }
                }
            }
        }
    }

    static void receiveSyncIsoObject(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        if (DebugOptions.instance.Network.Server.SyncIsoObject.getValue()) {
            int int0 = byteBuffer.getInt();
            int int1 = byteBuffer.getInt();
            int int2 = byteBuffer.getInt();
            byte byte0 = byteBuffer.get();
            byte byte1 = byteBuffer.get();
            byte byte2 = byteBuffer.get();
            if (byte1 == 1) {
                IsoGridSquare isoGridSquare = ServerMap.instance.getGridSquare(int0, int1, int2);
                if (isoGridSquare != null && byte0 >= 0 && byte0 < isoGridSquare.getObjects().size()) {
                    isoGridSquare.getObjects().get(byte0).syncIsoObject(true, byte2, udpConnection, byteBuffer);
                } else if (isoGridSquare != null) {
                    DebugLog.log("SyncIsoObject: index=" + byte0 + " is invalid x,y,z=" + int0 + "," + int1 + "," + int2);
                } else {
                    DebugLog.log("SyncIsoObject: sq is null x,y,z=" + int0 + "," + int1 + "," + int2);
                }
            }
        }
    }

    static void receiveSyncIsoObjectReq(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        short _short = byteBuffer.getShort();
        if (_short <= 50 && _short > 0) {
            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
            PacketTypes.PacketType.SyncIsoObjectReq.doPacket(byteBufferWriter);
            byteBufferWriter.putShort(_short);

            for (int int0 = 0; int0 < _short; int0++) {
                int int1 = byteBuffer.getInt();
                int int2 = byteBuffer.getInt();
                int int3 = byteBuffer.getInt();
                byte _byte = byteBuffer.get();
                IsoGridSquare isoGridSquare = ServerMap.instance.getGridSquare(int1, int2, int3);
                if (isoGridSquare != null && _byte >= 0 && _byte < isoGridSquare.getObjects().size()) {
                    isoGridSquare.getObjects().get(_byte).syncIsoObjectSend(byteBufferWriter);
                } else if (isoGridSquare != null) {
                    byteBufferWriter.putInt(isoGridSquare.getX());
                    byteBufferWriter.putInt(isoGridSquare.getY());
                    byteBufferWriter.putInt(isoGridSquare.getZ());
                    byteBufferWriter.putByte(_byte);
                    byteBufferWriter.putByte((byte)0);
                    byteBufferWriter.putByte((byte)0);
                } else {
                    byteBufferWriter.putInt(int1);
                    byteBufferWriter.putInt(int2);
                    byteBufferWriter.putInt(int3);
                    byteBufferWriter.putByte(_byte);
                    byteBufferWriter.putByte((byte)2);
                    byteBufferWriter.putByte((byte)0);
                }
            }

            PacketTypes.PacketType.SyncIsoObjectReq.send(udpConnection);
        }
    }

    static void receiveSyncObjects(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        short _short = byteBuffer.getShort();
        if (_short == 1) {
            SyncObjectChunkHashes(byteBuffer, udpConnection);
        } else if (_short == 3) {
            SyncObjectsGridSquareRequest(byteBuffer, udpConnection);
        } else if (_short == 5) {
            SyncObjectsRequest(byteBuffer, udpConnection);
        }
    }

    public static void SyncObjectChunkHashes(ByteBuffer bb, UdpConnection connection) {
        short _short = bb.getShort();
        if (_short <= 10 && _short > 0) {
            ByteBufferWriter byteBufferWriter = connection.startPacket();
            PacketTypes.PacketType.SyncObjects.doPacket(byteBufferWriter);
            byteBufferWriter.putShort((short)2);
            int int0 = byteBufferWriter.bb.position();
            byteBufferWriter.putShort((short)0);
            int int1 = 0;

            for (int int2 = 0; int2 < _short; int2++) {
                int int3 = bb.getInt();
                int int4 = bb.getInt();
                long _long = bb.getLong();
                IsoChunk isoChunk = ServerMap.instance.getChunk(int3, int4);
                if (isoChunk != null) {
                    int1++;
                    byteBufferWriter.putShort((short)isoChunk.wx);
                    byteBufferWriter.putShort((short)isoChunk.wy);
                    byteBufferWriter.putLong(isoChunk.getHashCodeObjects());
                    int int5 = byteBufferWriter.bb.position();
                    byteBufferWriter.putShort((short)0);
                    int int6 = 0;

                    for (int int7 = int3 * 10; int7 < int3 * 10 + 10; int7++) {
                        for (int int8 = int4 * 10; int8 < int4 * 10 + 10; int8++) {
                            for (int int9 = 0; int9 <= 7; int9++) {
                                IsoGridSquare isoGridSquare = ServerMap.instance.getGridSquare(int7, int8, int9);
                                if (isoGridSquare == null) {
                                    break;
                                }

                                byteBufferWriter.putByte((byte)(isoGridSquare.getX() - isoChunk.wx * 10));
                                byteBufferWriter.putByte((byte)(isoGridSquare.getY() - isoChunk.wy * 10));
                                byteBufferWriter.putByte((byte)isoGridSquare.getZ());
                                byteBufferWriter.putInt((int)isoGridSquare.getHashCodeObjects());
                                int6++;
                            }
                        }
                    }

                    int int10 = byteBufferWriter.bb.position();
                    byteBufferWriter.bb.position(int5);
                    byteBufferWriter.putShort((short)int6);
                    byteBufferWriter.bb.position(int10);
                }
            }

            int int11 = byteBufferWriter.bb.position();
            byteBufferWriter.bb.position(int0);
            byteBufferWriter.putShort((short)int1);
            byteBufferWriter.bb.position(int11);
            PacketTypes.PacketType.SyncObjects.send(connection);
        }
    }

    public static void SyncObjectChunkHashes(IsoChunk ch, UdpConnection connection) {
        ByteBufferWriter byteBufferWriter = connection.startPacket();
        PacketTypes.PacketType.SyncObjects.doPacket(byteBufferWriter);
        byteBufferWriter.putShort((short)2);
        byteBufferWriter.putShort((short)1);
        byteBufferWriter.putShort((short)ch.wx);
        byteBufferWriter.putShort((short)ch.wy);
        byteBufferWriter.putLong(ch.getHashCodeObjects());
        int int0 = byteBufferWriter.bb.position();
        byteBufferWriter.putShort((short)0);
        int int1 = 0;

        for (int int2 = ch.wx * 10; int2 < ch.wx * 10 + 10; int2++) {
            for (int int3 = ch.wy * 10; int3 < ch.wy * 10 + 10; int3++) {
                for (int int4 = 0; int4 <= 7; int4++) {
                    IsoGridSquare isoGridSquare = ServerMap.instance.getGridSquare(int2, int3, int4);
                    if (isoGridSquare == null) {
                        break;
                    }

                    byteBufferWriter.putByte((byte)(isoGridSquare.getX() - ch.wx * 10));
                    byteBufferWriter.putByte((byte)(isoGridSquare.getY() - ch.wy * 10));
                    byteBufferWriter.putByte((byte)isoGridSquare.getZ());
                    byteBufferWriter.putInt((int)isoGridSquare.getHashCodeObjects());
                    int1++;
                }
            }
        }

        int int5 = byteBufferWriter.bb.position();
        byteBufferWriter.bb.position(int0);
        byteBufferWriter.putShort((short)int1);
        byteBufferWriter.bb.position(int5);
        PacketTypes.PacketType.SyncObjects.send(connection);
    }

    public static void SyncObjectsGridSquareRequest(ByteBuffer bb, UdpConnection connection) {
        short _short = bb.getShort();
        if (_short <= 100 && _short > 0) {
            ByteBufferWriter byteBufferWriter = connection.startPacket();
            PacketTypes.PacketType.SyncObjects.doPacket(byteBufferWriter);
            byteBufferWriter.putShort((short)4);
            int int0 = byteBufferWriter.bb.position();
            byteBufferWriter.putShort((short)0);
            int int1 = 0;

            for (int int2 = 0; int2 < _short; int2++) {
                int int3 = bb.getInt();
                int int4 = bb.getInt();
                byte _byte = bb.get();
                IsoGridSquare isoGridSquare = ServerMap.instance.getGridSquare(int3, int4, _byte);
                if (isoGridSquare != null) {
                    int1++;
                    byteBufferWriter.putInt(int3);
                    byteBufferWriter.putInt(int4);
                    byteBufferWriter.putByte((byte)_byte);
                    byteBufferWriter.putByte((byte)isoGridSquare.getObjects().size());
                    byteBufferWriter.putInt(0);
                    int int5 = byteBufferWriter.bb.position();

                    for (int int6 = 0; int6 < isoGridSquare.getObjects().size(); int6++) {
                        byteBufferWriter.putLong(isoGridSquare.getObjects().get(int6).customHashCode());
                    }

                    int int7 = byteBufferWriter.bb.position();
                    byteBufferWriter.bb.position(int5 - 4);
                    byteBufferWriter.putInt(int7);
                    byteBufferWriter.bb.position(int7);
                }
            }

            int int8 = byteBufferWriter.bb.position();
            byteBufferWriter.bb.position(int0);
            byteBufferWriter.putShort((short)int1);
            byteBufferWriter.bb.position(int8);
            PacketTypes.PacketType.SyncObjects.send(connection);
        }
    }

    public static void SyncObjectsRequest(ByteBuffer bb, UdpConnection connection) {
        short _short = bb.getShort();
        if (_short <= 100 && _short > 0) {
            for (int int0 = 0; int0 < _short; int0++) {
                int int1 = bb.getInt();
                int int2 = bb.getInt();
                byte _byte = bb.get();
                long _long = bb.getLong();
                IsoGridSquare isoGridSquare = ServerMap.instance.getGridSquare(int1, int2, _byte);
                if (isoGridSquare != null) {
                    for (int int3 = 0; int3 < isoGridSquare.getObjects().size(); int3++) {
                        if (isoGridSquare.getObjects().get(int3).customHashCode() == _long) {
                            ByteBufferWriter byteBufferWriter = connection.startPacket();
                            PacketTypes.PacketType.SyncObjects.doPacket(byteBufferWriter);
                            byteBufferWriter.putShort((short)6);
                            byteBufferWriter.putInt(int1);
                            byteBufferWriter.putInt(int2);
                            byteBufferWriter.putByte((byte)_byte);
                            byteBufferWriter.putLong(_long);
                            byteBufferWriter.putByte((byte)isoGridSquare.getObjects().size());

                            for (int int4 = 0; int4 < isoGridSquare.getObjects().size(); int4++) {
                                byteBufferWriter.putLong(isoGridSquare.getObjects().get(int4).customHashCode());
                            }

                            try {
                                isoGridSquare.getObjects().get(int3).writeToRemoteBuffer(byteBufferWriter);
                            } catch (Throwable throwable) {
                                DebugLog.log("ERROR: GameServer.SyncObjectsRequest " + throwable.getMessage());
                                connection.cancelPacket();
                                break;
                            }

                            PacketTypes.PacketType.SyncObjects.send(connection);
                            break;
                        }
                    }
                }
            }
        }
    }

    static void receiveSyncDoorKey(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        byte _byte = byteBuffer.get();
        int int3 = byteBuffer.getInt();
        IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare(int0, int1, int2);
        if (isoGridSquare != null && _byte >= 0 && _byte < isoGridSquare.getObjects().size()) {
            IsoObject isoObject = isoGridSquare.getObjects().get(_byte);
            if (isoObject instanceof IsoDoor isoDoor) {
                isoDoor.keyId = int3;

                for (int int4 = 0; int4 < udpEngine.connections.size(); int4++) {
                    UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int4);
                    if (udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID()) {
                        ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                        PacketTypes.PacketType.SyncDoorKey.doPacket(byteBufferWriter);
                        byteBufferWriter.putInt(int0);
                        byteBufferWriter.putInt(int1);
                        byteBufferWriter.putInt(int2);
                        byteBufferWriter.putByte(_byte);
                        byteBufferWriter.putInt(int3);
                        PacketTypes.PacketType.SyncDoorKey.send(udpConnection0);
                    }
                }
            } else {
                DebugLog.log("SyncDoorKey: expected IsoDoor index=" + _byte + " is invalid x,y,z=" + int0 + "," + int1 + "," + int2);
            }
        } else if (isoGridSquare != null) {
            DebugLog.log("SyncDoorKey: index=" + _byte + " is invalid x,y,z=" + int0 + "," + int1 + "," + int2);
        } else {
            DebugLog.log("SyncDoorKey: sq is null x,y,z=" + int0 + "," + int1 + "," + int2);
        }
    }

    static void receiveSyncThumpable(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        byte byte0 = byteBuffer.get();
        int int3 = byteBuffer.getInt();
        byte byte1 = byteBuffer.get();
        int int4 = byteBuffer.getInt();
        IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare(int0, int1, int2);
        if (isoGridSquare != null && byte0 >= 0 && byte0 < isoGridSquare.getObjects().size()) {
            IsoObject isoObject = isoGridSquare.getObjects().get(byte0);
            if (isoObject instanceof IsoThumpable isoThumpable) {
                isoThumpable.lockedByCode = int3;
                isoThumpable.lockedByPadlock = byte1 == 1;
                isoThumpable.keyId = int4;

                for (int int5 = 0; int5 < udpEngine.connections.size(); int5++) {
                    UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int5);
                    if (udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID()) {
                        ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                        PacketTypes.PacketType.SyncThumpable.doPacket(byteBufferWriter);
                        byteBufferWriter.putInt(int0);
                        byteBufferWriter.putInt(int1);
                        byteBufferWriter.putInt(int2);
                        byteBufferWriter.putByte(byte0);
                        byteBufferWriter.putInt(int3);
                        byteBufferWriter.putByte(byte1);
                        byteBufferWriter.putInt(int4);
                        PacketTypes.PacketType.SyncThumpable.send(udpConnection0);
                    }
                }
            } else {
                DebugLog.log("SyncThumpable: expected IsoThumpable index=" + byte0 + " is invalid x,y,z=" + int0 + "," + int1 + "," + int2);
            }
        } else if (isoGridSquare != null) {
            DebugLog.log("SyncThumpable: index=" + byte0 + " is invalid x,y,z=" + int0 + "," + int1 + "," + int2);
        } else {
            DebugLog.log("SyncThumpable: sq is null x,y,z=" + int0 + "," + int1 + "," + int2);
        }
    }

    static void receiveRemoveItemFromSquare(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        int int3 = byteBuffer.getInt();
        IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare(int0, int1, int2);
        if (isoGridSquare != null && int3 >= 0 && int3 < isoGridSquare.getObjects().size()) {
            IsoObject isoObject0 = isoGridSquare.getObjects().get(int3);
            if (!(isoObject0 instanceof IsoWorldInventoryObject)) {
                IsoRegions.setPreviousFlags(isoGridSquare);
            }

            DebugLog.log(DebugType.Objects, "object: removing " + isoObject0 + " index=" + int3 + " " + int0 + "," + int1 + "," + int2);
            if (isoObject0 instanceof IsoWorldInventoryObject) {
                LoggerManager.getLogger("item")
                    .write(
                        udpConnection0.idStr
                            + " \""
                            + udpConnection0.username
                            + "\" floor -1 "
                            + int0
                            + ","
                            + int1
                            + ","
                            + int2
                            + " ["
                            + ((IsoWorldInventoryObject)isoObject0).getItem().getFullType()
                            + "]"
                    );
            } else {
                String string = isoObject0.getName() != null ? isoObject0.getName() : isoObject0.getObjectName();
                if (isoObject0.getSprite() != null && isoObject0.getSprite().getName() != null) {
                    string = string + " (" + isoObject0.getSprite().getName() + ")";
                }

                LoggerManager.getLogger("map")
                    .write(udpConnection0.idStr + " \"" + udpConnection0.username + "\" removed " + string + " at " + int0 + "," + int1 + "," + int2);
            }

            if (isoObject0.isTableSurface()) {
                for (int int4 = int3 + 1; int4 < isoGridSquare.getObjects().size(); int4++) {
                    IsoObject isoObject1 = isoGridSquare.getObjects().get(int4);
                    if (isoObject1.isTableTopObject() || isoObject1.isTableSurface()) {
                        isoObject1.setRenderYOffset(isoObject1.getRenderYOffset() - isoObject0.getSurfaceOffset());
                    }
                }
            }

            if (!(isoObject0 instanceof IsoWorldInventoryObject)) {
                LuaEventManager.triggerEvent("OnObjectAboutToBeRemoved", isoObject0);
            }

            if (!isoGridSquare.getObjects().contains(isoObject0)) {
                throw new IllegalArgumentException("OnObjectAboutToBeRemoved not allowed to remove the object");
            }

            isoObject0.removeFromWorld();
            isoObject0.removeFromSquare();
            isoGridSquare.RecalcAllWithNeighbours(true);
            if (!(isoObject0 instanceof IsoWorldInventoryObject)) {
                IsoWorld.instance.CurrentCell.checkHaveRoof(int0, int1);
                zombie.MapCollisionData.instance.squareChanged(isoGridSquare);
                PolygonalMap2.instance.squareChanged(isoGridSquare);
                ServerMap.instance.physicsCheck(int0, int1);
                IsoRegions.squareChanged(isoGridSquare, true);
                IsoGenerator.updateGenerator(isoGridSquare);
            }

            for (int int5 = 0; int5 < udpEngine.connections.size(); int5++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(int5);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()) {
                    ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                    PacketTypes.PacketType.RemoveItemFromSquare.doPacket(byteBufferWriter);
                    byteBufferWriter.putInt(int0);
                    byteBufferWriter.putInt(int1);
                    byteBufferWriter.putInt(int2);
                    byteBufferWriter.putInt(int3);
                    PacketTypes.PacketType.RemoveItemFromSquare.send(udpConnection1);
                }
            }
        }
    }

    public static int RemoveItemFromMap(IsoObject obj) {
        int int0 = obj.getSquare().getX();
        int int1 = obj.getSquare().getY();
        int int2 = obj.getSquare().getZ();
        int int3 = obj.getSquare().getObjects().indexOf(obj);
        IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare(int0, int1, int2);
        if (isoGridSquare != null && !(obj instanceof IsoWorldInventoryObject)) {
            IsoRegions.setPreviousFlags(isoGridSquare);
        }

        LuaEventManager.triggerEvent("OnObjectAboutToBeRemoved", obj);
        if (!obj.getSquare().getObjects().contains(obj)) {
            throw new IllegalArgumentException("OnObjectAboutToBeRemoved not allowed to remove the object");
        } else {
            obj.removeFromWorld();
            obj.removeFromSquare();
            if (isoGridSquare != null) {
                isoGridSquare.RecalcAllWithNeighbours(true);
            }

            if (!(obj instanceof IsoWorldInventoryObject)) {
                IsoWorld.instance.CurrentCell.checkHaveRoof(int0, int1);
                zombie.MapCollisionData.instance.squareChanged(isoGridSquare);
                PolygonalMap2.instance.squareChanged(isoGridSquare);
                ServerMap.instance.physicsCheck(int0, int1);
                IsoRegions.squareChanged(isoGridSquare, true);
                IsoGenerator.updateGenerator(isoGridSquare);
            }

            for (int int4 = 0; int4 < udpEngine.connections.size(); int4++) {
                UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(int4);
                if (udpConnection.RelevantTo((float)int0, (float)int1)) {
                    ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                    PacketTypes.PacketType.RemoveItemFromSquare.doPacket(byteBufferWriter);
                    byteBufferWriter.putInt(int0);
                    byteBufferWriter.putInt(int1);
                    byteBufferWriter.putInt(int2);
                    byteBufferWriter.putInt(int3);
                    PacketTypes.PacketType.RemoveItemFromSquare.send(udpConnection);
                }
            }

            return int3;
        }
    }

    public static void sendBloodSplatter(HandWeapon weapon, float x, float y, float z, Vector2 hitDir, boolean closeKilled, boolean radial) {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
            PacketTypes.PacketType.BloodSplatter.doPacket(byteBufferWriter);
            byteBufferWriter.putUTF(weapon != null ? weapon.getType() : "");
            byteBufferWriter.putFloat(x);
            byteBufferWriter.putFloat(y);
            byteBufferWriter.putFloat(z);
            byteBufferWriter.putFloat(hitDir.getX());
            byteBufferWriter.putFloat(hitDir.getY());
            byteBufferWriter.putByte((byte)(closeKilled ? 1 : 0));
            byteBufferWriter.putByte((byte)(radial ? 1 : 0));
            byte _byte = 0;
            if (weapon != null) {
                _byte = (byte)Math.max(weapon.getSplatNumber(), 1);
            }

            byteBufferWriter.putByte(_byte);
            PacketTypes.PacketType.BloodSplatter.send(udpConnection);
        }
    }

    static void receiveAddItemToMap(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        IsoObject isoObject = WorldItemTypes.createFromBuffer(byteBuffer);
        if (isoObject instanceof IsoFire && ServerOptions.instance.NoFire.getValue()) {
            DebugLog.log("user \"" + udpConnection0.username + "\" tried to start a fire");
        } else {
            isoObject.loadFromRemoteBuffer(byteBuffer);
            if (isoObject.square != null) {
                DebugLog.log(
                    DebugType.Objects,
                    "object: added "
                        + isoObject
                        + " index="
                        + isoObject.getObjectIndex()
                        + " "
                        + isoObject.getX()
                        + ","
                        + isoObject.getY()
                        + ","
                        + isoObject.getZ()
                );
                if (isoObject instanceof IsoWorldInventoryObject) {
                    LoggerManager.getLogger("item")
                        .write(
                            udpConnection0.idStr
                                + " \""
                                + udpConnection0.username
                                + "\" floor +1 "
                                + (int)isoObject.getX()
                                + ","
                                + (int)isoObject.getY()
                                + ","
                                + (int)isoObject.getZ()
                                + " ["
                                + ((IsoWorldInventoryObject)isoObject).getItem().getFullType()
                                + "]"
                        );
                } else {
                    String string = isoObject.getName() != null ? isoObject.getName() : isoObject.getObjectName();
                    if (isoObject.getSprite() != null && isoObject.getSprite().getName() != null) {
                        string = string + " (" + isoObject.getSprite().getName() + ")";
                    }

                    LoggerManager.getLogger("map")
                        .write(
                            udpConnection0.idStr
                                + " \""
                                + udpConnection0.username
                                + "\" added "
                                + string
                                + " at "
                                + isoObject.getX()
                                + ","
                                + isoObject.getY()
                                + ","
                                + isoObject.getZ()
                        );
                }

                isoObject.addToWorld();
                isoObject.square.RecalcProperties();
                if (!(isoObject instanceof IsoWorldInventoryObject)) {
                    isoObject.square.restackSheetRope();
                    IsoWorld.instance.CurrentCell.checkHaveRoof(isoObject.square.getX(), isoObject.square.getY());
                    zombie.MapCollisionData.instance.squareChanged(isoObject.square);
                    PolygonalMap2.instance.squareChanged(isoObject.square);
                    ServerMap.instance.physicsCheck(isoObject.square.x, isoObject.square.y);
                    IsoRegions.squareChanged(isoObject.square);
                    IsoGenerator.updateGenerator(isoObject.square);
                }

                for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                    UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
                    if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()
                        && udpConnection1.RelevantTo((float)isoObject.square.x, (float)isoObject.square.y)) {
                        ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                        PacketTypes.PacketType.AddItemToMap.doPacket(byteBufferWriter);
                        isoObject.writeToRemoteBuffer(byteBufferWriter);
                        PacketTypes.PacketType.AddItemToMap.send(udpConnection1);
                    }
                }

                if (!(isoObject instanceof IsoWorldInventoryObject)) {
                    LuaEventManager.triggerEvent("OnObjectAdded", isoObject);
                } else {
                    ((IsoWorldInventoryObject)isoObject).dropTime = zombie.GameTime.getInstance().getWorldAgeHours();
                }
            } else if (bDebug) {
                DebugLog.log("AddItemToMap: sq is null");
            }
        }
    }

    public static void disconnect(UdpConnection connection, String description) {
        if (connection.playerDownloadServer != null) {
            try {
                connection.playerDownloadServer.destroy();
            } catch (Exception exception) {
                exception.printStackTrace();
            }

            connection.playerDownloadServer = null;
        }

        RequestDataManager.getInstance().disconnect(connection);

        for (int int0 = 0; int0 < 4; int0++) {
            IsoPlayer isoPlayer = connection.players[int0];
            if (isoPlayer != null) {
                ChatServer.getInstance().disconnectPlayer(connection.playerIDs[int0]);
                disconnectPlayer(isoPlayer, connection);
            }

            connection.usernames[int0] = null;
            connection.players[int0] = null;
            connection.playerIDs[int0] = -1;
            connection.ReleventPos[int0] = null;
            connection.connectArea[int0] = null;
        }

        for (int int1 = 0; int1 < udpEngine.getMaxConnections(); int1++) {
            if (SlotToConnection[int1] == connection) {
                SlotToConnection[int1] = null;
            }
        }

        Iterator iterator = IDToAddressMap.entrySet().iterator();

        while (iterator.hasNext()) {
            Entry entry = (Entry)iterator.next();
            if ((Long)entry.getValue() == connection.getConnectedGUID()) {
                iterator.remove();
            }
        }

        if (!SteamUtils.isSteamModeEnabled()) {
            PublicServerUtil.updatePlayers();
        }

        if (CoopSlave.instance != null && connection.isCoopHost) {
            DebugLog.log("Host user disconnected, stopping the server");
            ServerMap.instance.QueueQuit();
        }

        if (bServer) {
            ConnectionManager.log("disconnect", description, connection);
        }
    }

    public static void addIncoming(short id, ByteBuffer bb, UdpConnection connection) {
        ZomboidNetData zomboidNetData = null;
        if (bb.limit() > 2048) {
            zomboidNetData = ZomboidNetDataPool.instance.getLong(bb.limit());
        } else {
            zomboidNetData = ZomboidNetDataPool.instance.get();
        }

        zomboidNetData.read(id, bb, connection);
        if (zomboidNetData.type == null) {
            try {
                if (ServerOptions.instance.AntiCheatProtectionType13.getValue() && PacketValidator.checkUser(connection)) {
                    PacketValidator.doKickUser(connection, String.valueOf(id), "Type13", null);
                }
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        } else {
            zomboidNetData.time = System.currentTimeMillis();
            if (zomboidNetData.type == PacketTypes.PacketType.PlayerUpdate || zomboidNetData.type == PacketTypes.PacketType.PlayerUpdateReliable) {
                MainLoopPlayerUpdateQ.add(zomboidNetData);
            } else if (zomboidNetData.type != PacketTypes.PacketType.VehiclesUnreliable && zomboidNetData.type != PacketTypes.PacketType.Vehicles) {
                MainLoopNetDataHighPriorityQ.add(zomboidNetData);
            } else {
                byte _byte = zomboidNetData.buffer.get(0);
                if (_byte == 9) {
                    MainLoopNetDataQ.add(zomboidNetData);
                } else {
                    MainLoopNetDataHighPriorityQ.add(zomboidNetData);
                }
            }
        }
    }

    public static void smashWindow(IsoWindow isoWindow, int action) {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            if (udpConnection.RelevantTo(isoWindow.getX(), isoWindow.getY())) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.SmashWindow.doPacket(byteBufferWriter);
                byteBufferWriter.putInt(isoWindow.square.getX());
                byteBufferWriter.putInt(isoWindow.square.getY());
                byteBufferWriter.putInt(isoWindow.square.getZ());
                byteBufferWriter.putByte((byte)isoWindow.square.getObjects().indexOf(isoWindow));
                byteBufferWriter.putByte((byte)action);
                PacketTypes.PacketType.SmashWindow.send(udpConnection);
            }
        }
    }

    static void receiveHitCharacter(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        try {
            HitCharacterPacket hitCharacterPacket = HitCharacterPacket.process(byteBuffer);
            if (hitCharacterPacket != null) {
                hitCharacterPacket.parse(byteBuffer, udpConnection);
                if (hitCharacterPacket.isConsistent() && hitCharacterPacket.validate(udpConnection)) {
                    DebugLog.Damage.trace(hitCharacterPacket.getDescription());
                    sendHitCharacter(hitCharacterPacket, udpConnection);
                    hitCharacterPacket.tryProcess();
                }
            }
        } catch (Exception exception) {
            DebugLog.Multiplayer.printException(exception, "ReceiveHitCharacter: failed", LogSeverity.Error);
        }
    }

    private static void sendHitCharacter(HitCharacterPacket hitCharacterPacket, UdpConnection udpConnection1) {
        DebugLog.Damage.trace(hitCharacterPacket.getDescription());

        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(_int);
            if (udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID() && hitCharacterPacket.isRelevant(udpConnection0)) {
                ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                PacketTypes.PacketType.HitCharacter.doPacket(byteBufferWriter);
                hitCharacterPacket.write(byteBufferWriter);
                PacketTypes.PacketType.HitCharacter.send(udpConnection0);
            }
        }
    }

    static void receiveZombieDeath(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        try {
            DeadZombiePacket deadZombiePacket = new DeadZombiePacket();
            deadZombiePacket.parse(byteBuffer, udpConnection);
            if (Core.bDebug) {
                DebugLog.Multiplayer.debugln("ReceiveZombieDeath: %s", deadZombiePacket.getDescription());
            }

            if (deadZombiePacket.isConsistent()) {
                if (deadZombiePacket.getZombie().isReanimatedPlayer()) {
                    sendZombieDeath(deadZombiePacket.getZombie());
                } else {
                    sendZombieDeath(deadZombiePacket);
                }

                deadZombiePacket.process();
            }
        } catch (Exception exception) {
            DebugLog.Multiplayer.printException(exception, "ReceiveZombieDeath: failed", LogSeverity.Error);
        }
    }

    public static void sendZombieDeath(IsoZombie zombie) {
        try {
            DeadZombiePacket deadZombiePacket = new DeadZombiePacket();
            deadZombiePacket.set(zombie);
            sendZombieDeath(deadZombiePacket);
        } catch (Exception exception) {
            DebugLog.Multiplayer.printException(exception, "SendZombieDeath: failed", LogSeverity.Error);
        }
    }

    private static void sendZombieDeath(DeadZombiePacket deadZombiePacket) {
        try {
            if (Core.bDebug) {
                DebugLog.Multiplayer.debugln("SendZombieDeath: %s", deadZombiePacket.getDescription());
            }

            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection.RelevantTo(deadZombiePacket.getZombie().getX(), deadZombiePacket.getZombie().getY())) {
                    ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                    PacketTypes.PacketType.ZombieDeath.doPacket(byteBufferWriter);

                    try {
                        deadZombiePacket.write(byteBufferWriter);
                        PacketTypes.PacketType.ZombieDeath.send(udpConnection);
                    } catch (Exception exception0) {
                        udpConnection.cancelPacket();
                        DebugLog.Multiplayer.printException(exception0, "SendZombieDeath: failed", LogSeverity.Error);
                    }
                }
            }
        } catch (Exception exception1) {
            DebugLog.Multiplayer.printException(exception1, "SendZombieDeath: failed", LogSeverity.Error);
        }
    }

    static void receivePlayerDeath(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        try {
            DeadPlayerPacket deadPlayerPacket = new DeadPlayerPacket();
            deadPlayerPacket.parse(byteBuffer, udpConnection);
            if (Core.bDebug) {
                DebugLog.Multiplayer.debugln("ReceivePlayerDeath: %s", deadPlayerPacket.getDescription());
            }

            String string = deadPlayerPacket.getPlayer().username;
            ChatServer.getInstance().disconnectPlayer(deadPlayerPacket.getPlayer().getOnlineID());
            ServerWorldDatabase.instance.saveTransactionID(string, 0);
            deadPlayerPacket.getPlayer().setTransactionID(0);
            transactionIDMap.put(string, 0);
            SafetySystemManager.clearSafety(deadPlayerPacket.getPlayer());
            if (deadPlayerPacket.getPlayer().accessLevel.equals("")
                && !ServerOptions.instance.Open.getValue()
                && ServerOptions.instance.DropOffWhiteListAfterDeath.getValue()) {
                try {
                    ServerWorldDatabase.instance.removeUser(string);
                } catch (SQLException sQLException) {
                    DebugLog.Multiplayer.printException(sQLException, "ReceivePlayerDeath: db failed", LogSeverity.Warning);
                }
            }

            if (deadPlayerPacket.isConsistent()) {
                deadPlayerPacket.id = deadPlayerPacket.getPlayer().getOnlineID();
                sendPlayerDeath(deadPlayerPacket, udpConnection);
                deadPlayerPacket.process();
            }

            deadPlayerPacket.getPlayer().setStateMachineLocked(true);
        } catch (Exception exception) {
            DebugLog.Multiplayer.printException(exception, "ReceivePlayerDeath: failed", LogSeverity.Error);
        }
    }

    public static void sendPlayerDeath(DeadPlayerPacket packet, UdpConnection connection) {
        if (Core.bDebug) {
            DebugLog.Multiplayer.debugln("SendPlayerDeath: %s", packet.getDescription());
        }

        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            if (connection == null || connection.getConnectedGUID() != udpConnection.getConnectedGUID()) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.PlayerDeath.doPacket(byteBufferWriter);
                packet.write(byteBufferWriter);
                PacketTypes.PacketType.PlayerDeath.send(udpConnection);
            }
        }
    }

    static void receivePlayerDamage(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        try {
            short _short = byteBuffer.getShort();
            float _float = byteBuffer.getFloat();
            IsoPlayer isoPlayer = getPlayerFromConnection(udpConnection, _short);
            if (isoPlayer != null) {
                isoPlayer.getBodyDamage().load(byteBuffer, IsoWorld.getWorldVersion());
                isoPlayer.getStats().setPain(_float);
                if (Core.bDebug) {
                    DebugLog.Multiplayer.debugln("ReceivePlayerDamage: \"%s\" %f", isoPlayer.getUsername(), isoPlayer.getBodyDamage().getOverallBodyHealth());
                }

                sendPlayerDamage(isoPlayer, udpConnection);
            }
        } catch (Exception exception) {
            DebugLog.Multiplayer.printException(exception, "ReceivePlayerDamage: failed", LogSeverity.Error);
        }
    }

    public static void sendPlayerDamage(IsoPlayer player, UdpConnection connection) {
        if (Core.bDebug) {
            DebugLog.Multiplayer.debugln("SendPlayerDamage: \"%s\" %f", player.getUsername(), player.getBodyDamage().getOverallBodyHealth());
        }

        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            if (connection.getConnectedGUID() != udpConnection.getConnectedGUID()) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.PlayerDamage.doPacket(byteBufferWriter);

                try {
                    byteBufferWriter.putShort(player.getOnlineID());
                    byteBufferWriter.putFloat(player.getStats().getPain());
                    player.getBodyDamage().save(byteBufferWriter.bb);
                    PacketTypes.PacketType.PlayerDamage.send(udpConnection);
                } catch (Exception exception) {
                    udpConnection.cancelPacket();
                    DebugLog.Multiplayer.printException(exception, "SendPlayerDamage: failed", LogSeverity.Error);
                }
            }
        }
    }

    static void receiveSyncInjuries(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        try {
            SyncInjuriesPacket syncInjuriesPacket = new SyncInjuriesPacket();
            syncInjuriesPacket.parse(byteBuffer, udpConnection);
            DebugLog.Damage.trace(syncInjuriesPacket.getDescription());
            if (syncInjuriesPacket.process()) {
                syncInjuriesPacket.id = syncInjuriesPacket.player.getOnlineID();
                sendPlayerInjuries(udpConnection, syncInjuriesPacket);
            }
        } catch (Exception exception) {
            DebugLog.Multiplayer.printException(exception, "ReceivePlayerInjuries: failed", LogSeverity.Error);
        }
    }

    private static void sendPlayerInjuries(UdpConnection udpConnection, SyncInjuriesPacket syncInjuriesPacket) {
        ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
        PacketTypes.PacketType.SyncInjuries.doPacket(byteBufferWriter);
        syncInjuriesPacket.write(byteBufferWriter);
        PacketTypes.PacketType.SyncInjuries.send(udpConnection);
    }

    static void receiveKeepAlive(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        MPDebugInfo.instance.serverPacket(byteBuffer, udpConnection);
    }

    static void receiveRemoveCorpseFromMap(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        RemoveCorpseFromMap removeCorpseFromMap = new RemoveCorpseFromMap();
        removeCorpseFromMap.parse(byteBuffer, udpConnection0);
        if (removeCorpseFromMap.isConsistent()) {
            removeCorpseFromMap.process();

            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID() && removeCorpseFromMap.isRelevant(udpConnection1)) {
                    ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                    PacketTypes.PacketType.RemoveCorpseFromMap.doPacket(byteBufferWriter);
                    removeCorpseFromMap.write(byteBufferWriter);
                    PacketTypes.PacketType.RemoveCorpseFromMap.send(udpConnection1);
                }
            }
        }
    }

    public static void sendRemoveCorpseFromMap(IsoDeadBody deadBody) {
        RemoveCorpseFromMap removeCorpseFromMap = new RemoveCorpseFromMap();
        removeCorpseFromMap.set(deadBody);
        DebugLog.Death.trace(removeCorpseFromMap.getDescription());

        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
            PacketTypes.PacketType.RemoveCorpseFromMap.doPacket(byteBufferWriter);
            removeCorpseFromMap.write(byteBufferWriter);
            PacketTypes.PacketType.RemoveCorpseFromMap.send(udpConnection);
        }
    }

    static void receiveEventPacket(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        try {
            EventPacket eventPacket = new EventPacket();
            eventPacket.parse(byteBuffer, udpConnection0);

            for (UdpConnection udpConnection1 : udpEngine.connections) {
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID() && eventPacket.isRelevant(udpConnection1)) {
                    ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                    PacketTypes.PacketType.EventPacket.doPacket(byteBufferWriter);
                    eventPacket.write(byteBufferWriter);
                    PacketTypes.PacketType.EventPacket.send(udpConnection1);
                }
            }
        } catch (Exception exception) {
            DebugLog.Multiplayer.printException(exception, "ReceiveEvent: failed", LogSeverity.Error);
        }
    }

    static void receiveActionPacket(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        try {
            ActionPacket actionPacket = new ActionPacket();
            actionPacket.parse(byteBuffer, udpConnection0);

            for (UdpConnection udpConnection1 : udpEngine.connections) {
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID() && actionPacket.isRelevant(udpConnection1)) {
                    ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                    PacketTypes.PacketType.ActionPacket.doPacket(byteBufferWriter);
                    actionPacket.write(byteBufferWriter);
                    PacketTypes.PacketType.ActionPacket.send(udpConnection1);
                }
            }
        } catch (Exception exception) {
            DebugLog.Multiplayer.printException(exception, "ReceiveAction: failed", LogSeverity.Error);
        }
    }

    static void receiveKillZombie(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        try {
            short _short = byteBuffer.getShort();
            boolean _boolean = byteBuffer.get() != 0;
            DebugLog.Death.trace("id=%d, isFallOnFront=%b", _short, _boolean);
            IsoZombie isoZombie = ServerMap.instance.ZombieMap.get(_short);
            if (isoZombie != null) {
                isoZombie.setFallOnFront(_boolean);
                isoZombie.becomeCorpse();
            } else {
                DebugLog.Multiplayer.error("ReceiveKillZombie: zombie not found");
            }
        } catch (Exception exception) {
            DebugLog.Multiplayer.printException(exception, "ReceiveKillZombie: failed", LogSeverity.Error);
        }
    }

    public static void receiveEatBody(ByteBuffer bb, UdpConnection connection, short packetType) {
        try {
            if (Core.bDebug) {
                DebugLog.log(DebugType.Multiplayer, "ReceiveEatBody");
            }

            short _short = bb.getShort();
            IsoZombie isoZombie = ServerMap.instance.ZombieMap.get(_short);
            if (isoZombie == null) {
                DebugLog.Multiplayer.error("ReceiveEatBody: zombie " + _short + " not found");
                return;
            }

            for (UdpConnection udpConnection : udpEngine.connections) {
                if (udpConnection.RelevantTo(isoZombie.x, isoZombie.y)) {
                    if (Core.bDebug) {
                        DebugLog.log(DebugType.Multiplayer, "SendEatBody");
                    }

                    ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                    PacketTypes.PacketType.EatBody.doPacket(byteBufferWriter);
                    bb.position(0);
                    byteBufferWriter.bb.put(bb);
                    PacketTypes.PacketType.EatBody.send(udpConnection);
                }
            }
        } catch (Exception exception) {
            DebugLog.Multiplayer.printException(exception, "ReceiveEatBody: failed", LogSeverity.Error);
        }
    }

    public static void receiveSyncRadioData(ByteBuffer bb, UdpConnection connection, short packetType) {
        try {
            boolean _boolean = bb.get() == 1;
            int int0 = bb.getInt();
            int[] int1 = new int[int0];

            for (int int2 = 0; int2 < int0; int2++) {
                int1[int2] = bb.getInt();
            }

            RakVoice.SetChannelsRouting(connection.getConnectedGUID(), _boolean, int1, (short)int0);

            for (UdpConnection udpConnection : udpEngine.connections) {
                if (udpConnection != connection && connection.players[0] != null) {
                    ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                    PacketTypes.PacketType.SyncRadioData.doPacket(byteBufferWriter);
                    byteBufferWriter.putShort(connection.players[0].OnlineID);
                    bb.position(0);
                    byteBufferWriter.bb.put(bb);
                    PacketTypes.PacketType.SyncRadioData.send(udpConnection);
                }
            }
        } catch (Exception exception) {
            DebugLog.Multiplayer.printException(exception, "SyncRadioData: failed", LogSeverity.Error);
        }
    }

    public static void receiveThump(ByteBuffer bb, UdpConnection connection, short packetType) {
        try {
            if (Core.bDebug) {
                DebugLog.log(DebugType.Multiplayer, "ReceiveThump");
            }

            short _short = bb.getShort();
            IsoZombie isoZombie = ServerMap.instance.ZombieMap.get(_short);
            if (isoZombie == null) {
                DebugLog.Multiplayer.error("ReceiveThump: zombie " + _short + " not found");
                return;
            }

            for (UdpConnection udpConnection : udpEngine.connections) {
                if (udpConnection.RelevantTo(isoZombie.x, isoZombie.y)) {
                    ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                    PacketTypes.PacketType.Thump.doPacket(byteBufferWriter);
                    bb.position(0);
                    byteBufferWriter.bb.put(bb);
                    PacketTypes.PacketType.Thump.send(udpConnection);
                }
            }
        } catch (Exception exception) {
            DebugLog.Multiplayer.printException(exception, "ReceiveEatBody: failed", LogSeverity.Error);
        }
    }

    public static void sendWorldSound(UdpConnection connection, zombie.WorldSoundManager.WorldSound sound) {
        ByteBufferWriter byteBufferWriter = connection.startPacket();
        PacketTypes.PacketType.WorldSound.doPacket(byteBufferWriter);

        try {
            byteBufferWriter.putInt(sound.x);
            byteBufferWriter.putInt(sound.y);
            byteBufferWriter.putInt(sound.z);
            byteBufferWriter.putInt(sound.radius);
            byteBufferWriter.putInt(sound.volume);
            byteBufferWriter.putByte((byte)(sound.stresshumans ? 1 : 0));
            byteBufferWriter.putFloat(sound.zombieIgnoreDist);
            byteBufferWriter.putFloat(sound.stressMod);
            byteBufferWriter.putByte((byte)(sound.sourceIsZombie ? 1 : 0));
            PacketTypes.PacketType.WorldSound.send(connection);
        } catch (Exception exception) {
            DebugLog.Sound.printException(exception, "SendWorldSound: failed", LogSeverity.Error);
            connection.cancelPacket();
        }
    }

    public static void sendWorldSound(zombie.WorldSoundManager.WorldSound sound, UdpConnection connection) {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            if ((connection == null || connection.getConnectedGUID() != udpConnection.getConnectedGUID()) && udpConnection.isFullyConnected()) {
                IsoPlayer isoPlayer = getAnyPlayerFromConnection(udpConnection);
                if (isoPlayer != null && udpConnection.RelevantTo((float)sound.x, (float)sound.y, (float)sound.radius)) {
                    sendWorldSound(udpConnection, sound);
                }
            }
        }
    }

    static void receiveWorldSound(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        int int3 = byteBuffer.getInt();
        int int4 = byteBuffer.getInt();
        boolean boolean0 = byteBuffer.get() == 1;
        float float0 = byteBuffer.getFloat();
        float float1 = byteBuffer.getFloat();
        boolean boolean1 = byteBuffer.get() == 1;
        DebugLog.Sound.noise("x=%d y=%d z=%d, radius=%d", int0, int1, int2, int3);
        zombie.WorldSoundManager.WorldSound worldSound = zombie.WorldSoundManager.instance
            .addSound(null, int0, int1, int2, int3, int4, boolean0, float0, float1, boolean1, false, true);
        if (worldSound != null) {
            sendWorldSound(worldSound, udpConnection);
        }
    }

    public static void kick(UdpConnection connection, String description, String reason) {
        DebugLog.General.warn("The player " + connection.username + " was kicked. The reason was " + description + ", " + reason);
        ConnectionManager.log("kick", reason, connection);
        ByteBufferWriter byteBufferWriter = connection.startPacket();

        try {
            PacketTypes.PacketType.Kicked.doPacket(byteBufferWriter);
            byteBufferWriter.putUTF(description);
            byteBufferWriter.putUTF(reason);
            PacketTypes.PacketType.Kicked.send(connection);
        } catch (Exception exception) {
            DebugLog.Multiplayer.printException(exception, "Kick: failed", LogSeverity.Error);
            connection.cancelPacket();
        }
    }

    private static void sendStartRain(UdpConnection udpConnection) {
        ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
        PacketTypes.PacketType.StartRain.doPacket(byteBufferWriter);
        byteBufferWriter.putInt(RainManager.randRainMin);
        byteBufferWriter.putInt(RainManager.randRainMax);
        byteBufferWriter.putFloat(RainManager.RainDesiredIntensity);
        PacketTypes.PacketType.StartRain.send(udpConnection);
    }

    public static void startRain() {
        if (udpEngine != null) {
            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
                sendStartRain(udpConnection);
            }
        }
    }

    private static void sendStopRain(UdpConnection udpConnection) {
        ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
        PacketTypes.PacketType.StopRain.doPacket(byteBufferWriter);
        PacketTypes.PacketType.StopRain.send(udpConnection);
    }

    public static void stopRain() {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            sendStopRain(udpConnection);
        }
    }

    private static void sendWeather(UdpConnection udpConnection) {
        zombie.GameTime gameTime = zombie.GameTime.getInstance();
        ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
        PacketTypes.PacketType.Weather.doPacket(byteBufferWriter);
        byteBufferWriter.putByte((byte)gameTime.getDawn());
        byteBufferWriter.putByte((byte)gameTime.getDusk());
        byteBufferWriter.putByte((byte)(gameTime.isThunderDay() ? 1 : 0));
        byteBufferWriter.putFloat(gameTime.Moon);
        byteBufferWriter.putFloat(gameTime.getAmbientMin());
        byteBufferWriter.putFloat(gameTime.getAmbientMax());
        byteBufferWriter.putFloat(gameTime.getViewDistMin());
        byteBufferWriter.putFloat(gameTime.getViewDistMax());
        byteBufferWriter.putFloat(IsoWorld.instance.getGlobalTemperature());
        byteBufferWriter.putUTF(IsoWorld.instance.getWeather());
        ErosionMain.getInstance().sendState(byteBufferWriter.bb);
        PacketTypes.PacketType.Weather.send(udpConnection);
    }

    public static void sendWeather() {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            sendWeather(udpConnection);
        }
    }

    private static boolean isInSameFaction(IsoPlayer isoPlayer0, IsoPlayer isoPlayer1) {
        Faction faction0 = Faction.getPlayerFaction(isoPlayer0);
        Faction faction1 = Faction.getPlayerFaction(isoPlayer1);
        return faction0 != null && faction0 == faction1;
    }

    private static boolean isInSameSafehouse(IsoPlayer isoPlayer1, IsoPlayer isoPlayer0) {
        ArrayList arrayList = SafeHouse.getSafehouseList();

        for (int _int = 0; _int < arrayList.size(); _int++) {
            SafeHouse safeHouse = (SafeHouse)arrayList.get(_int);
            if (safeHouse.playerAllowed(isoPlayer1.getUsername()) && safeHouse.playerAllowed(isoPlayer0.getUsername())) {
                return true;
            }
        }

        return false;
    }

    private static boolean isAnyPlayerInSameFaction(UdpConnection udpConnection, IsoPlayer isoPlayer1) {
        for (int _int = 0; _int < 4; _int++) {
            IsoPlayer isoPlayer0 = udpConnection.players[_int];
            if (isoPlayer0 != null && isInSameFaction(isoPlayer0, isoPlayer1)) {
                return true;
            }
        }

        return false;
    }

    private static boolean isAnyPlayerInSameSafehouse(UdpConnection udpConnection, IsoPlayer isoPlayer1) {
        for (int _int = 0; _int < 4; _int++) {
            IsoPlayer isoPlayer0 = udpConnection.players[_int];
            if (isoPlayer0 != null && isInSameSafehouse(isoPlayer0, isoPlayer1)) {
                return true;
            }
        }

        return false;
    }

    private static boolean shouldSendWorldMapPlayerPosition(UdpConnection udpConnection1, IsoPlayer isoPlayer) {
        if (isoPlayer != null && !isoPlayer.isDead()) {
            UdpConnection udpConnection0 = getConnectionFromPlayer(isoPlayer);
            if (udpConnection0 == null || udpConnection0 == udpConnection1 || !udpConnection0.isFullyConnected()) {
                return false;
            } else if (udpConnection1.accessLevel > 1) {
                return true;
            } else {
                int _int = ServerOptions.getInstance().MapRemotePlayerVisibility.getValue();
                return _int != 2 ? true : isAnyPlayerInSameFaction(udpConnection1, isoPlayer) || isAnyPlayerInSameSafehouse(udpConnection1, isoPlayer);
            }
        } else {
            return false;
        }
    }

    private static void sendWorldMapPlayerPosition(UdpConnection udpConnection) {
        tempPlayers.clear();

        for (int int0 = 0; int0 < Players.size(); int0++) {
            IsoPlayer isoPlayer0 = (IsoPlayer)Players.get(int0);
            if (shouldSendWorldMapPlayerPosition(udpConnection, isoPlayer0)) {
                tempPlayers.add(isoPlayer0);
            }
        }

        if (!tempPlayers.isEmpty()) {
            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
            PacketTypes.PacketType.WorldMapPlayerPosition.doPacket(byteBufferWriter);
            byteBufferWriter.putBoolean(false);
            byteBufferWriter.putShort((short)tempPlayers.size());

            for (int int1 = 0; int1 < tempPlayers.size(); int1++) {
                IsoPlayer isoPlayer1 = (IsoPlayer)tempPlayers.get(int1);
                WorldMapRemotePlayer worldMapRemotePlayer = WorldMapRemotePlayers.instance.getOrCreatePlayer(isoPlayer1);
                worldMapRemotePlayer.setPlayer(isoPlayer1);
                byteBufferWriter.putShort(worldMapRemotePlayer.getOnlineID());
                byteBufferWriter.putShort(worldMapRemotePlayer.getChangeCount());
                byteBufferWriter.putFloat(worldMapRemotePlayer.getX());
                byteBufferWriter.putFloat(worldMapRemotePlayer.getY());
            }

            PacketTypes.PacketType.WorldMapPlayerPosition.send(udpConnection);
        }
    }

    public static void sendWorldMapPlayerPosition() {
        int int0 = ServerOptions.getInstance().MapRemotePlayerVisibility.getValue();

        for (int int1 = 0; int1 < udpEngine.connections.size(); int1++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(int1);
            if (int0 != 1 || udpConnection.accessLevel != 1) {
                sendWorldMapPlayerPosition(udpConnection);
            }
        }
    }

    public static void receiveWorldMapPlayerPosition(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        short short0 = byteBuffer.getShort();
        tempPlayers.clear();

        for (int int0 = 0; int0 < short0; int0++) {
            short short1 = byteBuffer.getShort();
            IsoPlayer isoPlayer0 = (IsoPlayer)IDToPlayerMap.get(short1);
            if (isoPlayer0 != null && shouldSendWorldMapPlayerPosition(udpConnection, isoPlayer0)) {
                tempPlayers.add(isoPlayer0);
            }
        }

        if (!tempPlayers.isEmpty()) {
            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
            PacketTypes.PacketType.WorldMapPlayerPosition.doPacket(byteBufferWriter);
            byteBufferWriter.putBoolean(true);
            byteBufferWriter.putShort((short)tempPlayers.size());

            for (int int1 = 0; int1 < tempPlayers.size(); int1++) {
                IsoPlayer isoPlayer1 = (IsoPlayer)tempPlayers.get(int1);
                WorldMapRemotePlayer worldMapRemotePlayer = WorldMapRemotePlayers.instance.getOrCreatePlayer(isoPlayer1);
                worldMapRemotePlayer.setPlayer(isoPlayer1);
                byteBufferWriter.putShort(worldMapRemotePlayer.getOnlineID());
                byteBufferWriter.putShort(worldMapRemotePlayer.getChangeCount());
                byteBufferWriter.putUTF(worldMapRemotePlayer.getUsername());
                byteBufferWriter.putUTF(worldMapRemotePlayer.getForename());
                byteBufferWriter.putUTF(worldMapRemotePlayer.getSurname());
                byteBufferWriter.putUTF(worldMapRemotePlayer.getAccessLevel());
                byteBufferWriter.putFloat(worldMapRemotePlayer.getX());
                byteBufferWriter.putFloat(worldMapRemotePlayer.getY());
                byteBufferWriter.putBoolean(worldMapRemotePlayer.isInvisible());
            }

            PacketTypes.PacketType.WorldMapPlayerPosition.send(udpConnection);
        }
    }

    private static void syncClock(UdpConnection udpConnection) {
        zombie.GameTime gameTime = zombie.GameTime.getInstance();
        ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
        PacketTypes.PacketType.SyncClock.doPacket(byteBufferWriter);
        byteBufferWriter.putBoolean(bFastForward);
        byteBufferWriter.putFloat(gameTime.getTimeOfDay());
        byteBufferWriter.putInt(gameTime.getNightsSurvived());
        PacketTypes.PacketType.SyncClock.send(udpConnection);
    }

    public static void syncClock() {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            syncClock(udpConnection);
        }
    }

    public static void sendServerCommand(String string0, String string1, KahluaTable kahluaTable, UdpConnection udpConnection) {
        ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
        PacketTypes.PacketType.ClientCommand.doPacket(byteBufferWriter);
        byteBufferWriter.putUTF(string0);
        byteBufferWriter.putUTF(string1);
        if (kahluaTable != null && !kahluaTable.isEmpty()) {
            byteBufferWriter.putByte((byte)1);

            try {
                KahluaTableIterator kahluaTableIterator = kahluaTable.iterator();

                while (kahluaTableIterator.advance()) {
                    if (!TableNetworkUtils.canSave(kahluaTableIterator.getKey(), kahluaTableIterator.getValue())) {
                        DebugLog.log("ERROR: sendServerCommand: can't save key,value=" + kahluaTableIterator.getKey() + "," + kahluaTableIterator.getValue());
                    }
                }

                TableNetworkUtils.save(kahluaTable, byteBufferWriter.bb);
            } catch (IOException iOException) {
                iOException.printStackTrace();
            }
        } else {
            byteBufferWriter.putByte((byte)0);
        }

        PacketTypes.PacketType.ClientCommand.send(udpConnection);
    }

    public static void sendServerCommand(String string0, String string1, KahluaTable kahluaTable) {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            sendServerCommand(string0, string1, kahluaTable, udpConnection);
        }
    }

    public static void sendServerCommandV(String string0, String string1, Object... object0) {
        if (object0.length == 0) {
            sendServerCommand(string0, string1, (KahluaTable)null);
        } else if (object0.length % 2 != 0) {
            DebugLog.log("ERROR: sendServerCommand called with invalid number of arguments (" + string0 + " " + string1 + ")");
        } else {
            KahluaTable kahluaTable = LuaManager.platform.newTable();

            for (byte _byte = 0; _byte < object0.length; _byte += 2) {
                Object object1 = object0[_byte + 1];
                if (object1 instanceof Float) {
                    kahluaTable.rawset(object0[_byte], ((Float)object1).doubleValue());
                } else if (object1 instanceof Integer) {
                    kahluaTable.rawset(object0[_byte], ((Integer)object1).doubleValue());
                } else if (object1 instanceof Short) {
                    kahluaTable.rawset(object0[_byte], ((Short)object1).doubleValue());
                } else {
                    kahluaTable.rawset(object0[_byte], object1);
                }
            }

            sendServerCommand(string0, string1, kahluaTable);
        }
    }

    public static void sendServerCommand(IsoPlayer isoPlayer, String string0, String string1, KahluaTable kahluaTable) {
        if (PlayerToAddressMap.containsKey(isoPlayer)) {
            long _long = (Long)PlayerToAddressMap.get(isoPlayer);
            UdpConnection udpConnection = udpEngine.getActiveConnection(_long);
            if (udpConnection != null) {
                sendServerCommand(string0, string1, kahluaTable, udpConnection);
            }
        }
    }

    public static ArrayList<IsoPlayer> getPlayers(ArrayList<IsoPlayer> players) {
        players.clear();

        for (int int0 = 0; int0 < udpEngine.connections.size(); int0++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(int0);

            for (int int1 = 0; int1 < 4; int1++) {
                IsoPlayer isoPlayer = udpConnection.players[int1];
                if (isoPlayer != null && isoPlayer.OnlineID != -1) {
                    players.add(isoPlayer);
                }
            }
        }

        return players;
    }

    public static ArrayList<IsoPlayer> getPlayers() {
        ArrayList arrayList = new ArrayList();
        return getPlayers(arrayList);
    }

    public static int getPlayerCount() {
        int int0 = 0;

        for (int int1 = 0; int1 < udpEngine.connections.size(); int1++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(int1);

            for (int int2 = 0; int2 < 4; int2++) {
                if (udpConnection.playerIDs[int2] != -1) {
                    int0++;
                }
            }
        }

        return int0;
    }

    public static void sendAmbient(String name, int x, int y, int radius, float volume) {
        DebugLog.log(DebugType.Sound, "ambient: sending " + name + " at " + x + "," + y + " radius=" + radius);

        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            IsoPlayer isoPlayer = getAnyPlayerFromConnection(udpConnection);
            if (isoPlayer != null) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.AddAmbient.doPacket(byteBufferWriter);
                byteBufferWriter.putUTF(name);
                byteBufferWriter.putInt(x);
                byteBufferWriter.putInt(y);
                byteBufferWriter.putInt(radius);
                byteBufferWriter.putFloat(volume);
                PacketTypes.PacketType.AddAmbient.send(udpConnection);
            }
        }
    }

    static void receiveChangeSafety(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        try {
            SafetyPacket safetyPacket = new SafetyPacket();
            safetyPacket.parse(byteBuffer, udpConnection);
            safetyPacket.log(udpConnection, "ReceiveChangeSafety");
            safetyPacket.process();
        } catch (Exception exception) {
            DebugLog.Multiplayer.printException(exception, "ReceiveZombieDeath: failed", LogSeverity.Error);
        }
    }

    public static void sendChangeSafety(Safety safety) {
        try {
            SafetyPacket safetyPacket = new SafetyPacket(safety);
            safetyPacket.log(null, "SendChangeSafety");

            for (UdpConnection udpConnection : udpEngine.connections) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.ChangeSafety.doPacket(byteBufferWriter);
                safetyPacket.write(byteBufferWriter);
                PacketTypes.PacketType.ChangeSafety.send(udpConnection);
            }
        } catch (Exception exception) {
            DebugLog.Multiplayer.printException(exception, "SendChangeSafety: failed", LogSeverity.Error);
        }
    }

    static void receivePing(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        udpConnection.ping = true;
        answerPing(byteBuffer, udpConnection);
    }

    public static void updateOverlayForClients(IsoObject object, String spriteName, float r, float g, float b, float a, UdpConnection playerConnection) {
        if (udpEngine != null) {
            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection != null
                    && object.square != null
                    && udpConnection.RelevantTo((float)object.square.x, (float)object.square.y)
                    && (playerConnection == null || udpConnection.getConnectedGUID() != playerConnection.getConnectedGUID())) {
                    ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                    PacketTypes.PacketType.UpdateOverlaySprite.doPacket(byteBufferWriter);
                    zombie.GameWindow.WriteStringUTF(byteBufferWriter.bb, spriteName);
                    byteBufferWriter.putInt(object.getSquare().getX());
                    byteBufferWriter.putInt(object.getSquare().getY());
                    byteBufferWriter.putInt(object.getSquare().getZ());
                    byteBufferWriter.putFloat(r);
                    byteBufferWriter.putFloat(g);
                    byteBufferWriter.putFloat(b);
                    byteBufferWriter.putFloat(a);
                    byteBufferWriter.putInt(object.getSquare().getObjects().indexOf(object));
                    PacketTypes.PacketType.UpdateOverlaySprite.send(udpConnection);
                }
            }
        }
    }

    static void receiveUpdateOverlaySprite(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        String string = zombie.GameWindow.ReadStringUTF(byteBuffer);
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        float float0 = byteBuffer.getFloat();
        float float1 = byteBuffer.getFloat();
        float float2 = byteBuffer.getFloat();
        float float3 = byteBuffer.getFloat();
        int int3 = byteBuffer.getInt();
        IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare(int0, int1, int2);
        if (isoGridSquare != null && int3 < isoGridSquare.getObjects().size()) {
            try {
                IsoObject isoObject = isoGridSquare.getObjects().get(int3);
                if (isoObject != null && isoObject.setOverlaySprite(string, float0, float1, float2, float3, false)) {
                    updateOverlayForClients(isoObject, string, float0, float1, float2, float3, udpConnection);
                }
            } catch (Exception exception) {
            }
        }
    }

    public static void sendReanimatedZombieID(IsoPlayer player, IsoZombie zombie) {
        if (PlayerToAddressMap.containsKey(player)) {
            sendObjectChange(player, "reanimatedID", "ID", (double)zombie.OnlineID);
        }
    }

    static void receiveSyncSafehouse(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        SyncSafehousePacket syncSafehousePacket = new SyncSafehousePacket();
        syncSafehousePacket.parse(byteBuffer, udpConnection);
        if (syncSafehousePacket.validate(udpConnection)) {
            syncSafehousePacket.process();
            sendSafehouse(syncSafehousePacket, udpConnection);
            if (ChatServer.isInited()) {
                if (syncSafehousePacket.shouldCreateChat) {
                    ChatServer.getInstance().createSafehouseChat(syncSafehousePacket.safehouse.getId());
                }

                if (syncSafehousePacket.remove) {
                    ChatServer.getInstance().removeSafehouseChat(syncSafehousePacket.safehouse.getId());
                } else {
                    ChatServer.getInstance()
                        .syncSafehouseChatMembers(
                            syncSafehousePacket.safehouse.getId(), syncSafehousePacket.ownerUsername, syncSafehousePacket.safehouse.getPlayers()
                        );
                }
            }
        }
    }

    public static void receiveKickOutOfSafehouse(ByteBuffer bb, UdpConnection connection, short packetType) {
        try {
            IsoPlayer isoPlayer0 = (IsoPlayer)IDToPlayerMap.get(bb.getShort());
            if (isoPlayer0 == null) {
                return;
            }

            IsoPlayer isoPlayer1 = connection.players[0];
            if (isoPlayer1 == null) {
                return;
            }

            SafeHouse safeHouse = SafeHouse.hasSafehouse(isoPlayer1);
            if (safeHouse == null) {
                return;
            }

            if (!safeHouse.isOwner(isoPlayer1)) {
                return;
            }

            if (!safeHouse.playerAllowed(isoPlayer0)) {
                return;
            }

            UdpConnection udpConnection = getConnectionFromPlayer(isoPlayer0);
            if (udpConnection == null) {
                return;
            }

            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
            PacketTypes.PacketType.KickOutOfSafehouse.doPacket(byteBufferWriter);
            byteBufferWriter.putByte((byte)isoPlayer0.PlayerIndex);
            byteBufferWriter.putFloat((float)(safeHouse.getX() - 1));
            byteBufferWriter.putFloat((float)(safeHouse.getY() - 1));
            byteBufferWriter.putFloat(0.0F);
            PacketTypes.PacketType.KickOutOfSafehouse.send(udpConnection);
            if (isoPlayer0.getNetworkCharacterAI() != null) {
                isoPlayer0.getNetworkCharacterAI().resetSpeedLimiter();
            }

            if (isoPlayer0.isAsleep()) {
                isoPlayer0.setAsleep(false);
                isoPlayer0.setAsleepTime(0.0F);
                sendWakeUpPlayer(isoPlayer0, null);
            }
        } catch (Exception exception) {
            DebugLog.Multiplayer.printException(exception, "ReceiveKickOutOfSafehouse: failed", LogSeverity.Error);
        }
    }

    public static void sendSafehouse(SyncSafehousePacket packet, UdpConnection connection) {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            if (connection == null || udpConnection.getConnectedGUID() != connection.getConnectedGUID()) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.SyncSafehouse.doPacket(byteBufferWriter);
                packet.write(byteBufferWriter);
                PacketTypes.PacketType.SyncSafehouse.send(udpConnection);
            }
        }
    }

    public static void receiveRadioServerData(ByteBuffer bb, UdpConnection connection, short packetType) {
        ByteBufferWriter byteBufferWriter = connection.startPacket();
        PacketTypes.PacketType.RadioServerData.doPacket(byteBufferWriter);
        ZomboidRadio.getInstance().WriteRadioServerDataPacket(byteBufferWriter);
        PacketTypes.PacketType.RadioServerData.send(connection);
    }

    public static void receiveRadioDeviceDataState(ByteBuffer bb, UdpConnection connection, short packetType) {
        byte byte0 = bb.get();
        if (byte0 == 1) {
            int int0 = bb.getInt();
            int int1 = bb.getInt();
            int int2 = bb.getInt();
            int int3 = bb.getInt();
            IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare(int0, int1, int2);
            if (isoGridSquare != null && int3 >= 0 && int3 < isoGridSquare.getObjects().size()) {
                IsoObject isoObject = isoGridSquare.getObjects().get(int3);
                if (isoObject instanceof IsoWaveSignal) {
                    DeviceData deviceData0 = ((IsoWaveSignal)isoObject).getDeviceData();
                    if (deviceData0 != null) {
                        try {
                            deviceData0.receiveDeviceDataStatePacket(bb, null);
                        } catch (Exception exception0) {
                            System.out.print(exception0.getMessage());
                        }
                    }
                }
            }
        } else if (byte0 == 0) {
            byte byte1 = bb.get();
            IsoPlayer isoPlayer = getPlayerFromConnection(connection, byte1);
            byte byte2 = bb.get();
            if (isoPlayer != null) {
                Radio radio = null;
                if (byte2 == 1 && isoPlayer.getPrimaryHandItem() instanceof Radio) {
                    radio = (Radio)isoPlayer.getPrimaryHandItem();
                }

                if (byte2 == 2 && isoPlayer.getSecondaryHandItem() instanceof Radio) {
                    radio = (Radio)isoPlayer.getSecondaryHandItem();
                }

                if (radio != null && radio.getDeviceData() != null) {
                    try {
                        radio.getDeviceData().receiveDeviceDataStatePacket(bb, connection);
                    } catch (Exception exception1) {
                        System.out.print(exception1.getMessage());
                    }
                }
            }
        } else if (byte0 == 2) {
            short short0 = bb.getShort();
            short short1 = bb.getShort();
            BaseVehicle baseVehicle = VehicleManager.instance.getVehicleByID(short0);
            if (baseVehicle != null) {
                VehiclePart vehiclePart = baseVehicle.getPartByIndex(short1);
                if (vehiclePart != null) {
                    DeviceData deviceData1 = vehiclePart.getDeviceData();
                    if (deviceData1 != null) {
                        try {
                            deviceData1.receiveDeviceDataStatePacket(bb, null);
                        } catch (Exception exception2) {
                            System.out.print(exception2.getMessage());
                        }
                    }
                }
            }
        }
    }

    public static void sendIsoWaveSignal(
        long source, int sourceX, int sourceY, int channel, String msg, String guid, String codes, float r, float g, float b, int signalStrength, boolean isTV
    ) {
        WaveSignal waveSignal = new WaveSignal();
        waveSignal.set(sourceX, sourceY, channel, msg, guid, codes, r, g, b, signalStrength, isTV);

        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            if (source != udpConnection.getConnectedGUID()) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.WaveSignal.doPacket(byteBufferWriter);
                waveSignal.write(byteBufferWriter);
                PacketTypes.PacketType.WaveSignal.send(udpConnection);
            }
        }
    }

    public static void receiveWaveSignal(ByteBuffer bb, UdpConnection connection, short packetType) {
        WaveSignal waveSignal = new WaveSignal();
        waveSignal.parse(bb, connection);
        waveSignal.process(connection);
    }

    public static void receivePlayerListensChannel(ByteBuffer bb, UdpConnection connection, short packetType) {
        int _int = bb.getInt();
        boolean boolean0 = bb.get() == 1;
        boolean boolean1 = bb.get() == 1;
        ZomboidRadio.getInstance().PlayerListensChannel(_int, boolean0, boolean1);
    }

    public static void sendAlarm(int x, int y) {
        DebugLog.log(DebugType.Multiplayer, "SendAlarm at [ " + x + " , " + y + " ]");

        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            IsoPlayer isoPlayer = getAnyPlayerFromConnection(udpConnection);
            if (isoPlayer != null) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.AddAlarm.doPacket(byteBufferWriter);
                byteBufferWriter.putInt(x);
                byteBufferWriter.putInt(y);
                PacketTypes.PacketType.AddAlarm.send(udpConnection);
            }
        }
    }

    public static boolean isSpawnBuilding(BuildingDef def) {
        return SpawnPoints.instance.isSpawnBuilding(def);
    }

    private static void setFastForward(boolean _boolean) {
        if (_boolean != bFastForward) {
            bFastForward = _boolean;
            syncClock();
        }
    }

    static void receiveSendCustomColor(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        int int3 = byteBuffer.getInt();
        float float0 = byteBuffer.getFloat();
        float float1 = byteBuffer.getFloat();
        float float2 = byteBuffer.getFloat();
        float float3 = byteBuffer.getFloat();
        IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare(int0, int1, int2);
        if (isoGridSquare != null && int3 < isoGridSquare.getObjects().size()) {
            IsoObject isoObject = isoGridSquare.getObjects().get(int3);
            if (isoObject != null) {
                isoObject.setCustomColor(float0, float1, float2, float3);
            }
        }

        for (int int4 = 0; int4 < udpEngine.connections.size(); int4++) {
            UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int4);
            if (udpConnection0.RelevantTo((float)int0, (float)int1)
                && (udpConnection1 != null && udpConnection0.getConnectedGUID() != udpConnection1.getConnectedGUID() || udpConnection1 == null)) {
                ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                PacketTypes.PacketType.SendCustomColor.doPacket(byteBufferWriter);
                byteBufferWriter.putInt(int0);
                byteBufferWriter.putInt(int1);
                byteBufferWriter.putInt(int2);
                byteBufferWriter.putInt(int3);
                byteBufferWriter.putFloat(float0);
                byteBufferWriter.putFloat(float1);
                byteBufferWriter.putFloat(float2);
                byteBufferWriter.putFloat(float3);
                PacketTypes.PacketType.SendCustomColor.send(udpConnection0);
            }
        }
    }

    static void receiveSyncFurnace(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare(int0, int1, int2);
        if (isoGridSquare == null) {
            DebugLog.log("receiveFurnaceChange: square is null x,y,z=" + int0 + "," + int1 + "," + int2);
        } else {
            BSFurnace bSFurnace = null;

            for (int int3 = 0; int3 < isoGridSquare.getObjects().size(); int3++) {
                if (isoGridSquare.getObjects().get(int3) instanceof BSFurnace) {
                    bSFurnace = (BSFurnace)isoGridSquare.getObjects().get(int3);
                    break;
                }
            }

            if (bSFurnace == null) {
                DebugLog.log("receiveFurnaceChange: furnace is null x,y,z=" + int0 + "," + int1 + "," + int2);
            } else {
                bSFurnace.fireStarted = byteBuffer.get() == 1;
                bSFurnace.fuelAmount = byteBuffer.getFloat();
                bSFurnace.fuelDecrease = byteBuffer.getFloat();
                bSFurnace.heat = byteBuffer.getFloat();
                bSFurnace.sSprite = zombie.GameWindow.ReadString(byteBuffer);
                bSFurnace.sLitSprite = zombie.GameWindow.ReadString(byteBuffer);
                sendFuranceChange(bSFurnace, udpConnection);
            }
        }
    }

    static void receiveVehicles(ByteBuffer byteBuffer, UdpConnection udpConnection, short _short) {
        VehicleManager.instance.serverPacket(byteBuffer, udpConnection, _short);
    }

    static void receiveTimeSync(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        zombie.GameTime.receiveTimeSync(byteBuffer, udpConnection);
    }

    public static void sendFuranceChange(BSFurnace furnace, UdpConnection connection) {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            if (udpConnection.RelevantTo((float)furnace.square.x, (float)furnace.square.y)
                && (connection != null && udpConnection.getConnectedGUID() != connection.getConnectedGUID() || connection == null)) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.SyncFurnace.doPacket(byteBufferWriter);
                byteBufferWriter.putInt(furnace.square.x);
                byteBufferWriter.putInt(furnace.square.y);
                byteBufferWriter.putInt(furnace.square.z);
                byteBufferWriter.putByte((byte)(furnace.isFireStarted() ? 1 : 0));
                byteBufferWriter.putFloat(furnace.getFuelAmount());
                byteBufferWriter.putFloat(furnace.getFuelDecrease());
                byteBufferWriter.putFloat(furnace.getHeat());
                zombie.GameWindow.WriteString(byteBufferWriter.bb, furnace.sSprite);
                zombie.GameWindow.WriteString(byteBufferWriter.bb, furnace.sLitSprite);
                PacketTypes.PacketType.SyncFurnace.send(udpConnection);
            }
        }
    }

    static void receiveUserlog(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        String string = zombie.GameWindow.ReadString(byteBuffer);
        ArrayList arrayList = ServerWorldDatabase.instance.getUserlog(string);

        for (int int0 = 0; int0 < udpEngine.connections.size(); int0++) {
            UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int0);
            if (udpConnection0.getConnectedGUID() == udpConnection1.getConnectedGUID()) {
                ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                PacketTypes.PacketType.Userlog.doPacket(byteBufferWriter);
                byteBufferWriter.putInt(arrayList.size());
                byteBufferWriter.putUTF(string);

                for (int int1 = 0; int1 < arrayList.size(); int1++) {
                    Userlog userlog = (Userlog)arrayList.get(int1);
                    byteBufferWriter.putInt(Userlog.UserlogType.FromString(userlog.getType()).index());
                    byteBufferWriter.putUTF(userlog.getText());
                    byteBufferWriter.putUTF(userlog.getIssuedBy());
                    byteBufferWriter.putInt(userlog.getAmount());
                    byteBufferWriter.putUTF(userlog.getLastUpdate());
                }

                PacketTypes.PacketType.Userlog.send(udpConnection0);
            }
        }
    }

    static void receiveAddUserlog(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) throws SQLException {
        String string0 = zombie.GameWindow.ReadString(byteBuffer);
        String string1 = zombie.GameWindow.ReadString(byteBuffer);
        String string2 = zombie.GameWindow.ReadString(byteBuffer);
        ServerWorldDatabase.instance.addUserlog(string0, Userlog.UserlogType.FromString(string1), string2, udpConnection.username, 1);
        LoggerManager.getLogger("admin").write(udpConnection.username + " added log on user " + string0 + ", log: " + string2);
    }

    static void receiveRemoveUserlog(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) throws SQLException {
        String string0 = zombie.GameWindow.ReadString(byteBuffer);
        String string1 = zombie.GameWindow.ReadString(byteBuffer);
        String string2 = zombie.GameWindow.ReadString(byteBuffer);
        ServerWorldDatabase.instance.removeUserLog(string0, string1, string2);
        LoggerManager.getLogger("admin").write(udpConnection.username + " removed log on user " + string0 + ", type:" + string1 + ", log: " + string2);
    }

    static void receiveAddWarningPoint(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) throws SQLException {
        String string0 = zombie.GameWindow.ReadString(byteBuffer);
        String string1 = zombie.GameWindow.ReadString(byteBuffer);
        int int0 = byteBuffer.getInt();
        ServerWorldDatabase.instance.addWarningPoint(string0, string1, int0, udpConnection0.username);
        LoggerManager.getLogger("admin").write(udpConnection0.username + " added " + int0 + " warning point(s) on " + string0 + ", reason:" + string1);

        for (int int1 = 0; int1 < udpEngine.connections.size(); int1++) {
            UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(int1);
            if (udpConnection1.username.equals(string0)) {
                ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                PacketTypes.PacketType.WorldMessage.doPacket(byteBufferWriter);
                byteBufferWriter.putUTF(udpConnection0.username);
                byteBufferWriter.putUTF(" gave you " + int0 + " warning point(s), reason: " + string1 + " ");
                PacketTypes.PacketType.WorldMessage.send(udpConnection1);
            }
        }
    }

    public static void sendAdminMessage(String message, int x, int y, int z) {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            if (canSeePlayerStats(udpConnection)) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.MessageForAdmin.doPacket(byteBufferWriter);
                byteBufferWriter.putUTF(message);
                byteBufferWriter.putInt(x);
                byteBufferWriter.putInt(y);
                byteBufferWriter.putInt(z);
                PacketTypes.PacketType.MessageForAdmin.send(udpConnection);
            }
        }
    }

    static void receiveWakeUpPlayer(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        IsoPlayer isoPlayer = getPlayerFromConnection(udpConnection, byteBuffer.getShort());
        if (isoPlayer != null) {
            isoPlayer.setAsleep(false);
            isoPlayer.setAsleepTime(0.0F);
            sendWakeUpPlayer(isoPlayer, udpConnection);
        }
    }

    public static void sendWakeUpPlayer(IsoPlayer player, UdpConnection connection) {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            if (connection == null || udpConnection.getConnectedGUID() != connection.getConnectedGUID()) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.WakeUpPlayer.doPacket(byteBufferWriter);
                byteBufferWriter.putShort(player.getOnlineID());
                PacketTypes.PacketType.WakeUpPlayer.send(udpConnection);
            }
        }
    }

    static void receiveGetDBSchema(ByteBuffer var0, UdpConnection udpConnection1, short var2) {
        DBSchema dBSchema = ServerWorldDatabase.instance.getDBSchema();

        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(_int);
            if (udpConnection1 != null && udpConnection0.getConnectedGUID() == udpConnection1.getConnectedGUID()) {
                ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                PacketTypes.PacketType.GetDBSchema.doPacket(byteBufferWriter);
                HashMap hashMap0 = dBSchema.getSchema();
                byteBufferWriter.putInt(hashMap0.size());

                for (String string0 : hashMap0.keySet()) {
                    HashMap hashMap1 = (HashMap)hashMap0.get(string0);
                    byteBufferWriter.putUTF(string0);
                    byteBufferWriter.putInt(hashMap1.size());

                    for (String string1 : hashMap1.keySet()) {
                        byteBufferWriter.putUTF(string1);
                        byteBufferWriter.putUTF((String)hashMap1.get(string1));
                    }
                }

                PacketTypes.PacketType.GetDBSchema.send(udpConnection0);
            }
        }
    }

    static void receiveGetTableResult(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) throws SQLException {
        int int0 = byteBuffer.getInt();
        String string = zombie.GameWindow.ReadString(byteBuffer);
        ArrayList arrayList = ServerWorldDatabase.instance.getTableResult(string);

        for (int int1 = 0; int1 < udpEngine.connections.size(); int1++) {
            UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int1);
            if (udpConnection1 != null && udpConnection0.getConnectedGUID() == udpConnection1.getConnectedGUID()) {
                doTableResult(udpConnection0, string, arrayList, 0, int0);
            }
        }
    }

    private static void doTableResult(UdpConnection udpConnection, String string0, ArrayList<DBResult> arrayList, int int1, int int2) {
        int int0 = 0;
        boolean _boolean = true;
        ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
        PacketTypes.PacketType.GetTableResult.doPacket(byteBufferWriter);
        byteBufferWriter.putInt(int1);
        byteBufferWriter.putUTF(string0);
        if (arrayList.size() < int2) {
            byteBufferWriter.putInt(arrayList.size());
        } else if (arrayList.size() - int1 < int2) {
            byteBufferWriter.putInt(arrayList.size() - int1);
        } else {
            byteBufferWriter.putInt(int2);
        }

        for (int int3 = int1; int3 < arrayList.size(); int3++) {
            DBResult dBResult = null;

            try {
                dBResult = (DBResult)arrayList.get(int3);
                byteBufferWriter.putInt(dBResult.getColumns().size());
            } catch (Exception exception) {
                exception.printStackTrace();
            }

            for (String string1 : dBResult.getColumns()) {
                byteBufferWriter.putUTF(string1);
                byteBufferWriter.putUTF((String)dBResult.getValues().get(string1));
            }

            if (++int0 >= int2) {
                _boolean = false;
                PacketTypes.PacketType.GetTableResult.send(udpConnection);
                doTableResult(udpConnection, string0, arrayList, int1 + int0, int2);
                break;
            }
        }

        if (_boolean) {
            PacketTypes.PacketType.GetTableResult.send(udpConnection);
        }
    }

    static void receiveExecuteQuery(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) throws SQLException {
        if (udpConnection.accessLevel == 32) {
            try {
                String string = zombie.GameWindow.ReadString(byteBuffer);
                KahluaTable kahluaTable = LuaManager.platform.newTable();
                kahluaTable.load(byteBuffer, 195);
                ServerWorldDatabase.instance.executeQuery(string, kahluaTable);
            } catch (Throwable throwable) {
                throwable.printStackTrace();
            }
        }
    }

    static void receiveSendFactionInvite(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        String string0 = zombie.GameWindow.ReadString(byteBuffer);
        String string1 = zombie.GameWindow.ReadString(byteBuffer);
        String string2 = zombie.GameWindow.ReadString(byteBuffer);
        IsoPlayer isoPlayer = getPlayerByUserName(string2);
        if (isoPlayer != null) {
            Long _long = (Long)IDToAddressMap.get(isoPlayer.getOnlineID());

            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection.getConnectedGUID() == _long) {
                    ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                    PacketTypes.PacketType.SendFactionInvite.doPacket(byteBufferWriter);
                    byteBufferWriter.putUTF(string0);
                    byteBufferWriter.putUTF(string1);
                    PacketTypes.PacketType.SendFactionInvite.send(udpConnection);
                    break;
                }
            }
        }
    }

    static void receiveAcceptedFactionInvite(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        String string0 = zombie.GameWindow.ReadString(byteBuffer);
        String string1 = zombie.GameWindow.ReadString(byteBuffer);
        IsoPlayer isoPlayer = getPlayerByUserName(string1);
        Long _long = (Long)IDToAddressMap.get(isoPlayer.getOnlineID());

        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            if (udpConnection.getConnectedGUID() == _long) {
                Faction faction = Faction.getPlayerFaction(udpConnection.username);
                if (faction != null && faction.getName().equals(string0)) {
                    ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                    PacketTypes.PacketType.AcceptedFactionInvite.doPacket(byteBufferWriter);
                    byteBufferWriter.putUTF(string0);
                    byteBufferWriter.putUTF(string1);
                    PacketTypes.PacketType.AcceptedFactionInvite.send(udpConnection);
                }
            }
        }
    }

    static void receiveViewTickets(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) throws SQLException {
        String string = zombie.GameWindow.ReadString(byteBuffer);
        if ("".equals(string)) {
            string = null;
        }

        sendTickets(string, udpConnection);
    }

    private static void sendTickets(String string, UdpConnection udpConnection1) throws SQLException {
        ArrayList arrayList = ServerWorldDatabase.instance.getTickets(string);

        for (int int0 = 0; int0 < udpEngine.connections.size(); int0++) {
            UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int0);
            if (udpConnection0.getConnectedGUID() == udpConnection1.getConnectedGUID()) {
                ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                PacketTypes.PacketType.ViewTickets.doPacket(byteBufferWriter);
                byteBufferWriter.putInt(arrayList.size());

                for (int int1 = 0; int1 < arrayList.size(); int1++) {
                    DBTicket dBTicket = (DBTicket)arrayList.get(int1);
                    byteBufferWriter.putUTF(dBTicket.getAuthor());
                    byteBufferWriter.putUTF(dBTicket.getMessage());
                    byteBufferWriter.putInt(dBTicket.getTicketID());
                    if (dBTicket.getAnswer() != null) {
                        byteBufferWriter.putByte((byte)1);
                        byteBufferWriter.putUTF(dBTicket.getAnswer().getAuthor());
                        byteBufferWriter.putUTF(dBTicket.getAnswer().getMessage());
                        byteBufferWriter.putInt(dBTicket.getAnswer().getTicketID());
                    } else {
                        byteBufferWriter.putByte((byte)0);
                    }
                }

                PacketTypes.PacketType.ViewTickets.send(udpConnection0);
                break;
            }
        }
    }

    static void receiveAddTicket(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) throws SQLException {
        String string0 = zombie.GameWindow.ReadString(byteBuffer);
        String string1 = zombie.GameWindow.ReadString(byteBuffer);
        int _int = byteBuffer.getInt();
        if (_int == -1) {
            sendAdminMessage("user " + string0 + " added a ticket <LINE> <LINE> " + string1, -1, -1, -1);
        }

        ServerWorldDatabase.instance.addTicket(string0, string1, _int);
        sendTickets(string0, udpConnection);
    }

    static void receiveRemoveTicket(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) throws SQLException {
        int _int = byteBuffer.getInt();
        ServerWorldDatabase.instance.removeTicket(_int);
        sendTickets(null, udpConnection);
    }

    public static boolean sendItemListNet(
        UdpConnection ignore, IsoPlayer sender, ArrayList<InventoryItem> items, IsoPlayer receiver, String sessionID, String custom
    ) {
        for (int int0 = 0; int0 < udpEngine.connections.size(); int0++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(int0);
            if (ignore == null || udpConnection != ignore) {
                if (receiver != null) {
                    boolean _boolean = false;

                    for (int int1 = 0; int1 < udpConnection.players.length; int1++) {
                        IsoPlayer isoPlayer = udpConnection.players[int1];
                        if (isoPlayer != null && isoPlayer == receiver) {
                            _boolean = true;
                            break;
                        }
                    }

                    if (!_boolean) {
                        continue;
                    }
                }

                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.SendItemListNet.doPacket(byteBufferWriter);
                byteBufferWriter.putByte((byte)(receiver != null ? 1 : 0));
                if (receiver != null) {
                    byteBufferWriter.putShort(receiver.getOnlineID());
                }

                byteBufferWriter.putByte((byte)(sender != null ? 1 : 0));
                if (sender != null) {
                    byteBufferWriter.putShort(sender.getOnlineID());
                }

                zombie.GameWindow.WriteString(byteBufferWriter.bb, sessionID);
                byteBufferWriter.putByte((byte)(custom != null ? 1 : 0));
                if (custom != null) {
                    zombie.GameWindow.WriteString(byteBufferWriter.bb, custom);
                }

                try {
                    CompressIdenticalItems.save(byteBufferWriter.bb, items, null);
                } catch (Exception exception) {
                    exception.printStackTrace();
                    udpConnection.cancelPacket();
                    return false;
                }

                PacketTypes.PacketType.SendItemListNet.send(udpConnection);
            }
        }

        return true;
    }

    static void receiveSendItemListNet(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        IsoPlayer isoPlayer0 = null;
        if (byteBuffer.get() == 1) {
            isoPlayer0 = (IsoPlayer)IDToPlayerMap.get(byteBuffer.getShort());
        }

        IsoPlayer isoPlayer1 = null;
        if (byteBuffer.get() == 1) {
            isoPlayer1 = (IsoPlayer)IDToPlayerMap.get(byteBuffer.getShort());
        }

        String string0 = zombie.GameWindow.ReadString(byteBuffer);
        String string1 = null;
        if (byteBuffer.get() == 1) {
            string1 = zombie.GameWindow.ReadString(byteBuffer);
        }

        ArrayList arrayList = new ArrayList();

        try {
            CompressIdenticalItems.load(byteBuffer, 195, arrayList, null);
        } catch (Exception exception) {
            exception.printStackTrace();
        }

        if (isoPlayer0 == null) {
            LuaEventManager.triggerEvent("OnReceiveItemListNet", isoPlayer1, arrayList, isoPlayer0, string0, string1);
        } else {
            sendItemListNet(udpConnection, isoPlayer1, arrayList, isoPlayer0, string0, string1);
        }
    }

    public static void sendPlayerDamagedByCarCrash(IsoPlayer chr, float damage) {
        UdpConnection udpConnection = getConnectionFromPlayer(chr);
        if (udpConnection != null) {
            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
            PacketTypes.PacketType.PlayerDamageFromCarCrash.doPacket(byteBufferWriter);
            byteBufferWriter.putFloat(damage);
            PacketTypes.PacketType.PlayerDamageFromCarCrash.send(udpConnection);
        }
    }

    static void receiveClimateManagerPacket(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        ClimateManager climateManager = ClimateManager.getInstance();
        if (climateManager != null) {
            try {
                climateManager.receiveClimatePacket(byteBuffer, udpConnection);
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }
    }

    static void receivePassengerMap(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        PassengerMap.serverReceivePacket(byteBuffer, udpConnection);
    }

    static void receiveIsoRegionClientRequestFullUpdate(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        IsoRegions.receiveClientRequestFullDataChunks(byteBuffer, udpConnection);
    }

    private static String isWorldVersionUnsupported() {
        File file = new File(
            zombie.ZomboidFileSystem.instance.getSaveDir() + File.separator + "Multiplayer" + File.separator + ServerName + File.separator + "map_t.bin"
        );
        if (file.exists()) {
            DebugLog.log("checking server WorldVersion in map_t.bin");

            try {
                FileInputStream fileInputStream = new FileInputStream(file);

                String string0;
                label92: {
                    label91: {
                        String string1;
                        label109: {
                            try {
                                DataInputStream dataInputStream = new DataInputStream(fileInputStream);

                                label86: {
                                    label85: {
                                        label84: {
                                            try {
                                                byte byte0 = dataInputStream.readByte();
                                                byte byte1 = dataInputStream.readByte();
                                                byte byte2 = dataInputStream.readByte();
                                                byte byte3 = dataInputStream.readByte();
                                                if (byte0 == 71 && byte1 == 77 && byte2 == 84 && byte3 == 77) {
                                                    int _int = dataInputStream.readInt();
                                                    if (_int > 195) {
                                                        string0 = "The server savefile appears to be from a newer version of the game and cannot be loaded.";
                                                        break label85;
                                                    }

                                                    if (_int > 143) {
                                                        break label86;
                                                    }

                                                    string0 = "The server savefile appears to be from a pre-animations version of the game and cannot be loaded.\nDue to the extent of changes required to implement animations, saves from earlier versions are not compatible.";
                                                    break label84;
                                                }

                                                string1 = "The server savefile appears to be from an old version of the game and cannot be loaded.";
                                            } catch (Throwable throwable0) {
                                                try {
                                                    dataInputStream.close();
                                                } catch (Throwable throwable1) {
                                                    throwable0.addSuppressed(throwable1);
                                                }

                                                throw throwable0;
                                            }

                                            dataInputStream.close();
                                            break label109;
                                        }

                                        dataInputStream.close();
                                        break label91;
                                    }

                                    dataInputStream.close();
                                    break label92;
                                }

                                dataInputStream.close();
                            } catch (Throwable throwable2) {
                                try {
                                    fileInputStream.close();
                                } catch (Throwable throwable3) {
                                    throwable2.addSuppressed(throwable3);
                                }

                                throw throwable2;
                            }

                            fileInputStream.close();
                            return null;
                        }

                        fileInputStream.close();
                        return string1;
                    }

                    fileInputStream.close();
                    return string0;
                }

                fileInputStream.close();
                return string0;
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        } else {
            DebugLog.log("map_t.bin does not exist, cannot determine the server's WorldVersion.  This is ok the first time a server is started.");
        }

        return null;
    }

    public String getPoisonousBerry() {
        return this.poisonousBerry;
    }

    public void setPoisonousBerry(String _poisonousBerry) {
        this.poisonousBerry = _poisonousBerry;
    }

    public String getPoisonousMushroom() {
        return this.poisonousMushroom;
    }

    public void setPoisonousMushroom(String _poisonousMushroom) {
        this.poisonousMushroom = _poisonousMushroom;
    }

    public String getDifficulty() {
        return this.difficulty;
    }

    public void setDifficulty(String _difficulty) {
        this.difficulty = _difficulty;
    }

    public static void transmitBrokenGlass(IsoGridSquare sq) {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);

            try {
                if (udpConnection.RelevantTo((float)sq.getX(), (float)sq.getY())) {
                    ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                    PacketTypes.PacketType.AddBrokenGlass.doPacket(byteBufferWriter);
                    byteBufferWriter.putInt((short)sq.getX());
                    byteBufferWriter.putInt((short)sq.getY());
                    byteBufferWriter.putInt((short)sq.getZ());
                    PacketTypes.PacketType.AddBrokenGlass.send(udpConnection);
                }
            } catch (Throwable throwable) {
                udpConnection.cancelPacket();
                ExceptionLogger.logException(throwable);
            }
        }
    }

    public static boolean isServerDropPackets() {
        return droppedPackets > 0;
    }

    static void receiveSyncPerks(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        byte _byte = byteBuffer.get();
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        IsoPlayer isoPlayer0 = getPlayerFromConnection(udpConnection0, _byte);
        if (isoPlayer0 != null) {
            isoPlayer0.remoteSneakLvl = int0;
            isoPlayer0.remoteStrLvl = int1;
            isoPlayer0.remoteFitLvl = int2;

            for (int int3 = 0; int3 < udpEngine.connections.size(); int3++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(int3);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()) {
                    IsoPlayer isoPlayer1 = getAnyPlayerFromConnection(udpConnection0);
                    if (isoPlayer1 != null) {
                        try {
                            ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                            PacketTypes.PacketType.SyncPerks.doPacket(byteBufferWriter);
                            byteBufferWriter.putShort(isoPlayer0.OnlineID);
                            byteBufferWriter.putInt(int0);
                            byteBufferWriter.putInt(int1);
                            byteBufferWriter.putInt(int2);
                            PacketTypes.PacketType.SyncPerks.send(udpConnection1);
                        } catch (Throwable throwable) {
                            udpConnection0.cancelPacket();
                            ExceptionLogger.logException(throwable);
                        }
                    }
                }
            }
        }
    }

    static void receiveSyncWeight(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        byte _byte = byteBuffer.get();
        double _double = byteBuffer.getDouble();
        IsoPlayer isoPlayer0 = getPlayerFromConnection(udpConnection0, _byte);
        if (isoPlayer0 != null) {
            for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(_int);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()) {
                    IsoPlayer isoPlayer1 = getAnyPlayerFromConnection(udpConnection0);
                    if (isoPlayer1 != null) {
                        try {
                            ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                            PacketTypes.PacketType.SyncWeight.doPacket(byteBufferWriter);
                            byteBufferWriter.putShort(isoPlayer0.OnlineID);
                            byteBufferWriter.putDouble(_double);
                            PacketTypes.PacketType.SyncWeight.send(udpConnection1);
                        } catch (Throwable throwable) {
                            udpConnection0.cancelPacket();
                            ExceptionLogger.logException(throwable);
                        }
                    }
                }
            }
        }
    }

    static void receiveSyncEquippedRadioFreq(ByteBuffer byteBuffer, UdpConnection udpConnection0, short var2) {
        byte _byte = byteBuffer.get();
        int int0 = byteBuffer.getInt();
        ArrayList arrayList = new ArrayList();

        for (int int1 = 0; int1 < int0; int1++) {
            arrayList.add(byteBuffer.getInt());
        }

        IsoPlayer isoPlayer0 = getPlayerFromConnection(udpConnection0, _byte);
        if (isoPlayer0 != null) {
            for (int int2 = 0; int2 < udpEngine.connections.size(); int2++) {
                UdpConnection udpConnection1 = (UdpConnection)udpEngine.connections.get(int2);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID()) {
                    IsoPlayer isoPlayer1 = getAnyPlayerFromConnection(udpConnection0);
                    if (isoPlayer1 != null) {
                        try {
                            ByteBufferWriter byteBufferWriter = udpConnection1.startPacket();
                            PacketTypes.PacketType.SyncEquippedRadioFreq.doPacket(byteBufferWriter);
                            byteBufferWriter.putShort(isoPlayer0.OnlineID);
                            byteBufferWriter.putInt(int0);

                            for (int int3 = 0; int3 < arrayList.size(); int3++) {
                                byteBufferWriter.putInt((Integer)arrayList.get(int3));
                            }

                            PacketTypes.PacketType.SyncEquippedRadioFreq.send(udpConnection1);
                        } catch (Throwable throwable) {
                            udpConnection0.cancelPacket();
                            ExceptionLogger.logException(throwable);
                        }
                    }
                }
            }
        }
    }

    static void receiveGlobalModData(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        GlobalModData.instance.receive(byteBuffer);
    }

    static void receiveGlobalModDataRequest(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        GlobalModData.instance.receiveRequest(byteBuffer, udpConnection);
    }

    static void receiveSendSafehouseInvite(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        String string0 = zombie.GameWindow.ReadString(byteBuffer);
        String string1 = zombie.GameWindow.ReadString(byteBuffer);
        String string2 = zombie.GameWindow.ReadString(byteBuffer);
        IsoPlayer isoPlayer = getPlayerByUserName(string2);
        Long _long = (Long)IDToAddressMap.get(isoPlayer.getOnlineID());
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        int int3 = byteBuffer.getInt();

        for (int int4 = 0; int4 < udpEngine.connections.size(); int4++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(int4);
            if (udpConnection.getConnectedGUID() == _long) {
                ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
                PacketTypes.PacketType.SendSafehouseInvite.doPacket(byteBufferWriter);
                byteBufferWriter.putUTF(string0);
                byteBufferWriter.putUTF(string1);
                byteBufferWriter.putInt(int0);
                byteBufferWriter.putInt(int1);
                byteBufferWriter.putInt(int2);
                byteBufferWriter.putInt(int3);
                PacketTypes.PacketType.SendSafehouseInvite.send(udpConnection);
                break;
            }
        }
    }

    static void receiveAcceptedSafehouseInvite(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        String string0 = zombie.GameWindow.ReadString(byteBuffer);
        String string1 = zombie.GameWindow.ReadString(byteBuffer);
        String string2 = zombie.GameWindow.ReadString(byteBuffer);
        int int0 = byteBuffer.getInt();
        int int1 = byteBuffer.getInt();
        int int2 = byteBuffer.getInt();
        int int3 = byteBuffer.getInt();
        SafeHouse safeHouse = SafeHouse.getSafeHouse(int0, int1, int2, int3);
        if (safeHouse != null) {
            safeHouse.addPlayer(string2);
        } else {
            DebugLog.log(
                "WARN: player '"
                    + string2
                    + "' accepted the invitation, but the safehouse not found for x="
                    + int0
                    + " y="
                    + int1
                    + " w="
                    + int2
                    + " h="
                    + int3
            );
        }

        for (int int4 = 0; int4 < udpEngine.connections.size(); int4++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(int4);
            ByteBufferWriter byteBufferWriter = udpConnection.startPacket();
            PacketTypes.PacketType.AcceptedSafehouseInvite.doPacket(byteBufferWriter);
            byteBufferWriter.putUTF(string0);
            byteBufferWriter.putUTF(string1);
            byteBufferWriter.putUTF(string2);
            byteBufferWriter.putInt(int0);
            byteBufferWriter.putInt(int1);
            byteBufferWriter.putInt(int2);
            byteBufferWriter.putInt(int3);
            PacketTypes.PacketType.AcceptedSafehouseInvite.send(udpConnection);
        }
    }

    public static void sendRadioPostSilence() {
        for (int _int = 0; _int < udpEngine.connections.size(); _int++) {
            UdpConnection udpConnection = (UdpConnection)udpEngine.connections.get(_int);
            if (udpConnection.statistic.enable == 3) {
                sendShortStatistic(udpConnection);
            }
        }
    }

    public static void sendRadioPostSilence(UdpConnection c) {
        try {
            ByteBufferWriter byteBufferWriter = c.startPacket();
            PacketTypes.PacketType.RadioPostSilenceEvent.doPacket(byteBufferWriter);
            byteBufferWriter.putByte((byte)(ZomboidRadio.POST_RADIO_SILENCE ? 1 : 0));
            PacketTypes.PacketType.RadioPostSilenceEvent.send(c);
        } catch (Exception exception) {
            exception.printStackTrace();
            c.cancelPacket();
        }
    }

    static void receiveSneezeCough(ByteBuffer byteBuffer, UdpConnection udpConnection1, short var2) {
        short _short = byteBuffer.getShort();
        byte _byte = byteBuffer.get();
        IsoPlayer isoPlayer = (IsoPlayer)IDToPlayerMap.get(_short);
        if (isoPlayer != null) {
            float float0 = isoPlayer.x;
            float float1 = isoPlayer.y;
            int int0 = 0;

            for (int int1 = udpEngine.connections.size(); int0 < int1; int0++) {
                UdpConnection udpConnection0 = (UdpConnection)udpEngine.connections.get(int0);
                if (udpConnection1.getConnectedGUID() != udpConnection0.getConnectedGUID() && udpConnection0.RelevantTo(float0, float1)) {
                    ByteBufferWriter byteBufferWriter = udpConnection0.startPacket();
                    PacketTypes.PacketType.SneezeCough.doPacket(byteBufferWriter);
                    byteBufferWriter.putShort(_short);
                    byteBufferWriter.putByte(_byte);
                    PacketTypes.PacketType.SneezeCough.send(udpConnection0);
                }
            }
        }
    }

    static void receiveBurnCorpse(ByteBuffer byteBuffer, UdpConnection var1, short var2) {
        short short0 = byteBuffer.getShort();
        short short1 = byteBuffer.getShort();
        IsoPlayer isoPlayer = (IsoPlayer)IDToPlayerMap.get(short0);
        if (isoPlayer == null) {
            DebugLog.Network.warn("Player not found by id " + short0);
        } else {
            IsoDeadBody isoDeadBody = IsoDeadBody.getDeadBody(short1);
            if (isoDeadBody == null) {
                DebugLog.Network.warn("Corpse not found by id " + short1);
            } else {
                float _float = IsoUtils.DistanceTo(isoPlayer.x, isoPlayer.y, isoDeadBody.x, isoDeadBody.y);
                if (_float <= 1.8F) {
                    IsoFireManager.StartFire(isoDeadBody.getCell(), isoDeadBody.getSquare(), true, 100);
                } else {
                    DebugLog.Network.warn("Distance between player and corpse too big: " + _float);
                }
            }
        }
    }

    public static void sendValidatePacket(UdpConnection connection, boolean queued, boolean done, boolean details) {
        ByteBufferWriter byteBufferWriter = connection.startPacket();

        try {
            ValidatePacket validatePacket = new ValidatePacket();
            validatePacket.setSalt(connection.validator.getSalt(), queued, done, details);
            PacketTypes.PacketType.Validate.doPacket(byteBufferWriter);
            validatePacket.write(byteBufferWriter);
            PacketTypes.PacketType.Validate.send(connection);
            validatePacket.log(GameClient.connection, "send-packet");
        } catch (Exception exception) {
            connection.cancelPacket();
            DebugLog.Multiplayer.printException(exception, "SendValidatePacket: failed", LogSeverity.Error);
        }
    }

    static void receiveValidatePacket(ByteBuffer byteBuffer, UdpConnection udpConnection, short var2) {
        ValidatePacket validatePacket = new ValidatePacket();
        validatePacket.parse(byteBuffer, udpConnection);
        validatePacket.log(GameClient.connection, "receive-packet");
        if (validatePacket.isConsistent()) {
            validatePacket.process(udpConnection);
        }
    }

    private static final class CCFilter {
        String command;
        boolean allow;
        GameServer.CCFilter next;

        boolean matches(String string) {
            return this.command.equals(string) || "*".equals(this.command);
        }

        boolean passes(String string) {
            if (this.matches(string)) {
                return this.allow;
            } else {
                return this.next == null ? true : this.next.passes(string);
            }
        }
    }

    private static class DelayedConnection implements IZomboidPacket {
        public UdpConnection connection;
        public boolean connect;
        public String hostString;

        public DelayedConnection(UdpConnection udpConnection, boolean _boolean) {
            this.connection = udpConnection;
            this.connect = _boolean;
            if (_boolean) {
                try {
                    this.hostString = udpConnection.getInetSocketAddress().getHostString();
                } catch (Exception exception) {
                    exception.printStackTrace();
                }
            }
        }

        @Override
        public boolean isConnect() {
            return this.connect;
        }

        @Override
        public boolean isDisconnect() {
            return !this.connect;
        }
    }

    private static class s_performance {
        static final PerformanceProfileFrameProbe frameStep = new PerformanceProfileFrameProbe("GameServer.frameStep");
        static final PerformanceProfileProbe mainLoopDealWithNetData = new PerformanceProfileProbe("GameServer.mainLoopDealWithNetData");
        static final PerformanceProfileProbe RCONServerUpdate = new PerformanceProfileProbe("RCONServer.update");
    }
}
